c++14 Questions
2
Solved
I know that you can use static_cast<void>, but it just seems too verbose for me, and not reflecting the original intent that I want to discard a return value, not to cast it to anything.
Rece...
4
Solved
While playing around with compile-time string (variadic lists of char) manipulation, I needed to implement a way of checking if a compile-time string contained another (smaller) compile-time string...
Belletrist asked 10/2, 2015 at 13:32
7
Solved
C++11 gave us great std::array, which requires size to be known at compile time:
std::array<int, 3> myarray = {1, 2, 3};
Now, I happen to have some old short* buffers to wrap, whose size w...
4
Solved
There are a lot of *_v and *_t suffixes, like std::is_same_v, std::invoke_result_t, result_of_t and milions of other such functions.
Why do they exist at all? Is it beneficial in any context to exp...
Rood asked 11/9, 2023 at 17:32
1
Look at this example (godbolt):
void foo(int &par) {
auto l = [par]() {
decltype(par) x;
};
}
This program does not compile, because the par in decltype(par) refers to the parameter in foo,...
Avast asked 5/9, 2023 at 9:37
1
I was trying to reply to another answer and I found some difficulties while playing with lambdas and inheritance. Consider the following, minimal example:
template<typename Func>
struct Base:...
Herringbone asked 12/12, 2016 at 23:19
2
Solved
Apparently today, MSVC is trying its best to convince me to switch to clang. But I won't give up. Earlier I asked this question wondering how to declare std::make_unique as a friend of my class.
I...
Chemoreceptor asked 24/11, 2015 at 23:25
2
Solved
std::byte is defined in C++17 as:
enum class byte : unsigned char {};
I'm currently stuck at using C++14, and I wonder if I add the same definition in C++14 (in some non-std namespace, along with ...
Offshore asked 9/8, 2023 at 9:17
1
Solved
Consider the following code (godbolt link):
#include <cstdio>
int main() {
auto foo = operator new;
void* mem = foo(1);
printf("%p", mem);
}
This code compiles on GCC, Clang, a...
Runaway asked 28/7, 2023 at 12:44
2
Solved
How can I get the arity of an arbitrary function type used as a template parameter?
The function can be a normal function, a lambda or a functor. Example:
template<typename TFunc>
std::size...
2
Solved
Why rvalue reference template variable b<int> is able to bind to lvalue a?
#include <iostream>
int a = 3;
template<typename T>
T&& b = a;
int main() {
if(std::is_same_...
Maryjanemaryjo asked 3/5, 2023 at 12:56
5
Solved
I am in the middle of writing some generic code for a future library. I came across the following problem inside a template function. Consider the code below:
template<class F>
auto foo(F &a...
1
Solved
I was playing with the following code.
#include <iostream>
struct To
{
To() = default;
To(const struct From&) {std::cout << "Constructor called\n";}
To(const To&) ...
Grained asked 24/4, 2023 at 20:28
2
Solved
Inventing a discriminated union/tagged variant I conclude that there is particular need in such a feature as "make destructor trivial on some conditions at compile time". I mean some kind of SFINAE...
Midgut asked 17/6, 2015 at 5:9
3
Solved
I'm updating a class to C++14, and trying to figure out the simplest way to initialize all of the instance variables to zero on construction. Here's what I have so far:
class MyClass {
public:
in...
Helluva asked 5/2, 2017 at 5:50
1
In the following example, Abstract is a class template whose first parameter is a type and the second parameter is another template taking a bool along with any number of args.
template<bool,ty...
Wanids asked 20/2, 2018 at 18:22
5
Solved
The strings topic in the SO Documentation used to say, in the Remarks section:
Since C++14, instead of using "foo", it is recommended to use "foo"s, as s is a string literal, w...
Offshore asked 28/7, 2016 at 2:51
3
Solved
When I try to use a static const to initialize a unique_ptr, I get an "undefined reference" error. However, when I new a pointer using the same constant, the symbol seems to be magically defined.
...
Magnetron asked 24/1, 2018 at 17:38
2
#include <iostream>
class NoCopyMove {
public:
NoCopyMove(int a) : a_(a), b_(a) {}
NoCopyMove(int a, int b) : a_(a), b_(b) {}
NoCopyMove(const NoCopyMove&) = delete;
NoCopyMove&...
3
Solved
The lambda is used by std::function reference, but the value in the lambda cannot be changed. I don't know why? I've used references, but still can't achieve that.
#include <iostream>
#includ...
2
Who knows how to implement C++ std::make_index_sequence reverse version. To get - make_index_sequence_reverse<int, 5> = <4,3,2,1,0>. Thank you!
Laruelarum asked 18/7, 2018 at 18:30
8
Solved
Why is operator () of stateless functor not allowed to be static? Stateless lambda objects are convertible to pointers to free functions having the same signature as their operator ().
Stephan T. ...
Armory asked 25/9, 2015 at 6:53
2
Solved
Is there a reason for missing transparent (template <class K> at(K&& key);) in std::map?
Delphina asked 23/11, 2016 at 14:33
2
Solved
Does a constant reference member variable in an anonymous struct extend the lifetime of a temporary?
Consider the following code:
struct Temp{ int i = 0; };
Temp GetTemp() { return Temp{}; }
int main()
{
for (struct{Temp const & t; int counter;} v = {GetTemp(), 0};
v.counter < 10;
++v...
Vintner asked 20/1, 2023 at 12:59
5
Hi i am reading about expression in C++ and across the statement
Statement 0.0
Each expression has some non-reference type
The quoted statement is from en.cppreference.com/w/cpp/language/value_ca...
Automata asked 6/5, 2021 at 9:16
© 2022 - 2024 — McMap. All rights reserved.