c++14

constexpr non-static member function with non-constexpr constructor (gcc,clang differ)

偶尔善良 提交于 2020-01-03 08:09:49
问题 For this code: struct S { S(int m): m(m) {} constexpr int f() const { return m; } int m; }; int main() { S s(1); } it is compiled with no warnings or errors by clang 3.6, 3.7 and 3.8 with -std=c++14 . But in g++ 5.x the following errors occur: main.cpp:4:19: error: enclosing class of constexpr non-static member function 'int S::f() const' is not a literal type constexpr int f() const { return m; } ^ main.cpp:1:8: note: 'S' is not literal because: struct S ^ main.cpp:1:8: note: 'S' is not an

constexpr non-static member function with non-constexpr constructor (gcc,clang differ)

一笑奈何 提交于 2020-01-03 08:09:07
问题 For this code: struct S { S(int m): m(m) {} constexpr int f() const { return m; } int m; }; int main() { S s(1); } it is compiled with no warnings or errors by clang 3.6, 3.7 and 3.8 with -std=c++14 . But in g++ 5.x the following errors occur: main.cpp:4:19: error: enclosing class of constexpr non-static member function 'int S::f() const' is not a literal type constexpr int f() const { return m; } ^ main.cpp:1:8: note: 'S' is not literal because: struct S ^ main.cpp:1:8: note: 'S' is not an

Friend function template with automatic return type deduction cannot access a private member

。_饼干妹妹 提交于 2020-01-03 07:19:15
问题 Sorry for how complicated the title of this question is; I tried to describe the minimal SSCCE I constructed for this problem. I have the following code: #include <iostream> namespace fizz { template<typename... Ts> class bar { public: template<int I, typename... Us> friend auto foo(const bar<Us...> &); private: int i = 123; }; template<int I, typename... Ts> auto foo(const bar<Ts...> & b) { return b.i; } } int main() { std::cout << fizz::foo<1>(fizz::bar<int, float>{}); } This code compiles

Eliminate copies when constructing members of a class

江枫思渺然 提交于 2020-01-03 03:43:13
问题 For two arbitrary objects of type T and U that are composed into a class like so template <class T, class U> struct Comp { T t_m; U u_m; }; what would be the optimum (in terms of minimizing copy operations) way to construct them out of (available) temporaries ? I have considered "moving" them into my class Comp(T&& t, U&& u) : t_m(std::move(t)) , u_m(std::move(u)) { } but I don't know how well their move constructors behave or if they have any whatsoever . Since it seems that my class can be

Using custom allocator for AllocatorAwareContainer data members of a class

流过昼夜 提交于 2020-01-03 00:39:12
问题 Given a non-stateless custom allocator A (say, arena allocator, binded to some contiguous memory chunk of runtime-known size) and class S , containing a fileds of AllocatorAwareContainer types: struct S { A() = default; // another c-tors std::vector< T > v; std::shared_ptr< U > s; }; I want to use A for a subset (or even for all) AllocatorAwareContainer fields of class S . It is clear, that I should to provide one another template parameter for class S and change types of all the interesting

Using custom allocator for AllocatorAwareContainer data members of a class

坚强是说给别人听的谎言 提交于 2020-01-03 00:39:08
问题 Given a non-stateless custom allocator A (say, arena allocator, binded to some contiguous memory chunk of runtime-known size) and class S , containing a fileds of AllocatorAwareContainer types: struct S { A() = default; // another c-tors std::vector< T > v; std::shared_ptr< U > s; }; I want to use A for a subset (or even for all) AllocatorAwareContainer fields of class S . It is clear, that I should to provide one another template parameter for class S and change types of all the interesting

What are the syntax and semantics of C++ templated code?

余生颓废 提交于 2020-01-02 12:13:38
问题 template<typename T, size_t M, size_t K, size_t N, typename std::enable_if_t<std::is_floating_point<T>::value, T> = 0> void fastor2d(){//...} I copied this line of code from cpp-reference(only the std::enable_if part, i do need T and all three of the size_t 's), because i would like to use this function only when floating_types are used on it ... it does not compile. Could somebody explain to me, why, and what it even does? While i am at it, how do you call this function afterwards? Every

non-static template member : possible?

拜拜、爱过 提交于 2020-01-02 07:29:58
问题 Is it possible to create non-static template field in a class? If no, how to workaround? Such fields should be created at compile time as needed. Example I have a lot of B -class, like B1 , B2 , B3 . (In real case, they have more meaningful names.) I want to create a class D that has non-static template function add<BX>() that have to counter++ every time I call it, for each individual BX , for a certain instance of D. (In real case, it does somethings more complex.) Here is a working demo to

What's the life-time of a function parameter (citation needed)? [closed]

拜拜、爱过 提交于 2020-01-02 07:18:32
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Is the life-time of a function parameter equal of an unnamed temporary passed as an 'rvalue' reference (which is equal of the expression called the function)? My 'gcc' compiler shows that it is. But I want to see an actual standard document that states it too (possible the newest 'C++11' or 'C++14'

What's the life-time of a function parameter (citation needed)? [closed]

南笙酒味 提交于 2020-01-02 07:18:05
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Is the life-time of a function parameter equal of an unnamed temporary passed as an 'rvalue' reference (which is equal of the expression called the function)? My 'gcc' compiler shows that it is. But I want to see an actual standard document that states it too (possible the newest 'C++11' or 'C++14'