c++17

How to use experimental parallel STL in C++1z?

断了今生、忘了曾经 提交于 2019-12-22 08:35:45
问题 I want to try parallel STL of C++17. However, I can't find experimental/execution_policy in libc++. How can I try this? I'm trying http://en.cppreference.com/w/cpp/experimental/reduce, which says I should include these files, but I cannot find execution_policy. #include <experimental/execution_policy> After I install libc++ (I followed http://libcxx.llvm.org/docs/BuildingLibcxx.html), I tried the following commands, but in vain. $ clang++-3.5 -std=c++1z test.cpp -lc++experimental test.cpp:5

Why is there no std::move_if algorithm?

夙愿已清 提交于 2019-12-22 07:59:43
问题 I've seen a few places on the internet where they describe using std::copy_if with std::make_move_iterator , but if the iterator were to be a forward iterator, that would result in having valid but unspecified (VBU) objects scattered around the source container. Wouldn't it be better to have a std::move_if algorithm such that if an object is moved, then it would move the resulting VBU object to the end of the range, like that which is done in the std::remove_if algorithm, consolidating all of

Visual Studio not performing RVO when ternary operator is used and move/copy ctors are deleted

馋奶兔 提交于 2019-12-22 07:23:21
问题 Looking at below code sample I would expect it to perform mandatory copy elision as part of Return Value Optimization (RVO) and compile with C++17 (/std:c++17) but it compiles with an error on Visual Studio 2017 (I'm using VS17, 15.9.8 more specifically). class NoCopyOrMove { public: NoCopyOrMove() = default; NoCopyOrMove(int a, int b){} NoCopyOrMove(const NoCopyOrMove&) = delete; NoCopyOrMove& operator=(const NoCopyOrMove&) = delete; NoCopyOrMove(NoCopyOrMove&&) = delete; NoCopyOrMove&

Why auto is not allowed as function argument?

家住魔仙堡 提交于 2019-12-22 05:42:28
问题 From this question, it is clear that auto cannot be used as function argument. My question is why return type is allowed as auto but function arguments are not ? auto function(auto data) { //DOES something } Since, there are many benefits of auto coming in c++1z , then why not this ? 回答1: This syntax was proposed in the Concepts TS, which did not make it into C++17 for various reasons. Despite some critique I've outlined below, it has been added in C++20. Note: the following part of the

When explicitly initializing std::optional's, should I use nullopt? [closed]

别等时光非礼了梦想. 提交于 2019-12-22 05:19:14
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . An std::optional<T> can be initialized to the disengaged state like so: std::optional<int> oi { nullopt }; but also like so: std::optional<int> oi { }; and similarly for assignment ( oi = {} or oi = nullopt ). Other than personal preference / sense of aesthetics, is there a

Explicitly invoking `int` destructor - why is a type alias required? [duplicate]

橙三吉。 提交于 2019-12-22 05:10:55
问题 This question already has an answer here : Pseudo-destructor call does not destroy an object (1 answer) Closed 2 years ago . The following program... int main() { int{1}.~int(); } does not compile on (see conformance viewer) : clang++ trunk, with -std=c++1z g++ trunk, with -std=c++1z CL 19 2017 Introducing a type alias for int ... int main() { using X = int; int{1}.~X(); } ...makes the program valid on all previously mentioned compilers, without warnings (see conformance viewer) . Why is a

Are lock-free atomics address-free in practice?

拟墨画扇 提交于 2019-12-22 04:49:11
问题 Boost.Interprocess is a wonderful library that simplifies the usage of shared memory amongst different processes. It provides mutexes, condition variables, and semaphores, which allow for synchronization when writing and reading from the shared memory. However, in some situations these (relatively) performance-intensive synchronization mechanisms are not necessary - atomic operations suffice for my use case, and will likely give much better performance. Unfortunately, Boost.Interprocess does

Will template parameter deduction for constructors available since C++17 allow explicitly specify some of the class template arguments?

拟墨画扇 提交于 2019-12-22 04:43:17
问题 Apart from the most obvious usage of template parameter deduction for constructors, I can imagine some more complex use cases where we deduce only part of the parameters of the template class e.g.: std::pair<int> p(1, 2); // std::pair<int, int> Although this construct would be natural consequence of the deduction of template parameters in functions I couldn't find any example of this kind of usage. Maybe it's because of the ambiguity in case of classes with variadic template arguments? std:

C++ Default constructor not inherited with “using” when move and copy constructors present

六眼飞鱼酱① 提交于 2019-12-22 04:28:10
问题 class A{ public: A(){}; }; class B : public A{ public: using A::A; B(const B&) = default; B( B&&) = default; }; B b; The compiler (g++ (5.4.0-6ubuntu1) / c++11) says "no matching function for call to B::B()" and lists the copy and move constructors as candidates. If I comment those defaulted ones out then it compiles. What causes this? And what difference does it make that they are explicitly defaulted? If those 2 lines weren't there they would be defaulted anyway. 回答1: Before C++17, the

Passing lambda as template parameter to templated by function-pointer function

╄→尐↘猪︶ㄣ 提交于 2019-12-22 03:43:32
问题 Looks like I cannot pass a no-capture lambda as a template parameter to a templated by function-pointer function. Am I doing it the wrong way, or is it impossible? #include <iostream> // Function templated by function pointer template< void(*F)(int) > void fun( int i ) { F(i); } void f1( int i ) { std::cout << i << std::endl; } int main() { void(*f2)( int ) = []( int i ) { std::cout << i << std::endl; }; fun<f1>( 42 ); // THIS WORKS f2( 42 ); // THIS WORKS fun<f2>( 42 ); // THIS DOES NOT WORK