c++14

Allocator specialized for array types in c++14?

谁都会走 提交于 2021-02-08 01:26:41
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

那年仲夏 提交于 2021-02-08 01:24:22
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

落爺英雄遲暮 提交于 2021-02-08 01:23:08
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

孤人 提交于 2021-02-08 01:22:35
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

SFINAE to determine if a type has a potentially overloaded method

杀马特。学长 韩版系。学妹 提交于 2021-02-07 22:41:53
问题 I was looking for an SFINAE solution to check at compile time if a type has a method. My goal is to check if a type is a valid "duck type", but instead of a useless compile error, I want to use static_assert to provide an informative message. I found [this question], which provides a fairly good answer to my problem, except it fails when the type provides overload to the method: template<typename...> // parameter pack here using void_t = void; template<typename T, typename = void> struct has

how to block usage of std::make_shared<T>

橙三吉。 提交于 2021-02-07 21:54:46
问题 I know I can prevent ordinary heap allocation of custom class and its descendants by making the class's operator new private, but is there any way to prevent a user of a library from calling std::make_shared on a custom class (or its descendants)? Apparently, simply making the operator new private in a class does not stop it. Note that I do not want to completely prevent shared pointers from being created by any means, as I intend to still be able to produce a std::shared_ptr for my custom

Follow-up: What exactly is a variable in C++14/C++17?

ⅰ亾dé卋堺 提交于 2021-02-07 12:06:41
问题 As the title suggests, this question has been asked before. However, the answers pertained to C++03/0x(11). C++11 (N3337) says this about variables: [basic]/6: A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object. This may imply that variables are essentially named objects/references. However, in C++14/C++17, that last sentence was changed to The variable’s name, if any , denotes the

Passing a lambda with moved capture to function

此生再无相见时 提交于 2021-02-07 11:40:30
问题 I recently struggled with a bug hard to find for me. I tried to pass a lambda to a function taking a std::function object. The lambda was capturing a noncopyable object. I figured out, obviously some copy must happen in between all the passings. I came to this result because I always ended in an error: use of deleted function error. Here is the code which produces this error: void call_func(std::function<void()> func) { func(); } int main() { std::fstream fs{"test.txt", std::fstream::out};

Why to use std::move despite the parameter is an r-value reference

人盡茶涼 提交于 2021-02-07 06:25:44
问题 I am confused about using std::move() in below code: If I uncomment line at (2) the output would be: 1 2 3 but if I uncomment line at (1) output would be nothing which means that move constructor of std::vector was called! Why do we have to make another call to std::move at (1) to make move constructor of std::vector to be called? What I understood that std::move get the r-value of its parameter so, why we have to get the r-value of r-value at (1)? I think this line _v = rv; at (2) is more

Why to use std::move despite the parameter is an r-value reference

陌路散爱 提交于 2021-02-07 06:23:46
问题 I am confused about using std::move() in below code: If I uncomment line at (2) the output would be: 1 2 3 but if I uncomment line at (1) output would be nothing which means that move constructor of std::vector was called! Why do we have to make another call to std::move at (1) to make move constructor of std::vector to be called? What I understood that std::move get the r-value of its parameter so, why we have to get the r-value of r-value at (1)? I think this line _v = rv; at (2) is more