c++17

C++17 fold expression syntax?

独自空忆成欢 提交于 2019-11-30 19:47:44
I am trying to use compact fold expression without success. For instance here is a working C++17 code template <bool... B> struct Fold_And : std::integral_constant<bool, (B && ...)> { }; template <bool... B> constexpr auto Fold_And_v = Fold_And<B...>::value; template <typename V, typename... Vs> std::enable_if_t< Fold_And_v<std::is_floating_point_v<V>, std::is_floating_point_v<Vs>...> > foo(const V& v, const Vs&...) { } I want to translate it into a more compact form (not using the intermediate Fold_And ) template <typename V, typename... Vs> std::enable_if_t<std::is_floating_point_v<V> && ...

clang 3.6 fold expression left/right

时光毁灭记忆、已成空白 提交于 2019-11-30 19:42:06
I'm trying the fold expression with clang 3.6 '--std=c++1z', but something I don't quite get. The function that I'm testing is: auto minus = [](auto... args) { return (args - ...); }; ... std::cout << minus(10, 3, 2) << std::endl; according to n4191 , I'm expecting it expands as a left fold to (10 - 3) - 2 which gives result 5, however, the result is 9, which seems to be a right fold expansion, i.e. 10 - (3 - 2) Am I missing anything or mis-understand n4191? Thanks n4191 was revised by n4295 . According to that, an expression of the form (e op ...) is a unary right fold , and that is expanded

clang 4 build error on <functional> with c++1z

强颜欢笑 提交于 2019-11-30 19:35:18
I just updated my arch linux system to the latest which includes gcc 7.1.1. Trying to build this: #include <functional> int main(int argc, char** argv) { return 1; } using the command clang++ main.cpp -std=c++1z results in the error: In file included from main.cpp:1: In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/functional:60: In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/unordered_map:47: In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1

GCC is no longer supported - C++17 - Android Studio

懵懂的女人 提交于 2019-11-30 19:17:36
问题 I need to use C++17 compliant source files in my Android project. I added my .cpp files to the src/main/cpp folder. After the build, this error appears: Build command failed. Error while executing process /Users/khasan/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/Users/khasan/Projects/myapplication/app -B/Users/khasan/Projects/myapplication/app/.externalNativeBuild/cmake/debug/ arm64-v8a -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-21 -DCMAKE_LIBRARY_OUTPUT

Failure to deduce template argument std::function from lambda function

你说的曾经没有我的故事 提交于 2019-11-30 19:02:41
问题 While exploring templates in C++, I stumbled upon the example in the following code: #include <iostream> #include <functional> template <typename T> void call(std::function<void(T)> f, T v) { f(v); } int main(int argc, char const *argv[]) { auto foo = [](int i) { std::cout << i << std::endl; }; call(foo, 1); return 0; } To compile this program, I am using the GNU C++ Compiler g++: $ g++ --version // g++ (Ubuntu 6.5.0-1ubuntu1~16.04) 6.5.0 20181026 After compiling for C++11 , I get the

structured bindings and range-based-for; supress unused warning in gcc

我的未来我决定 提交于 2019-11-30 18:56:10
I want to traverse a map using structure bindings, ignoring the key: for (auto& [unused, val] : my_map) do_something(val); I have tried different options with gcc-7.2.0: // The warning is issued for ([[maybe_unused]] auto& [unused, val] : my_map) do_something(val); // Syntax error for (auto& [[[maybe_unused]] unused, val] : my_map) do_something(val); // The same two combinations above with [[gnu::unused]]. It seems that the [[maybe_unused]] attribute is not implemented yet for structure bindings. Is there any simple solution to this? Any macro, gcc/gnu extension, or any pragma to temporarily

clarification of specifics of P0137

房东的猫 提交于 2019-11-30 18:53:47
In the following code I have been meticulous in the following of the standard's words (plus in the light of the wording of P0137 ) on object lifetimes. Note that all memory allocation is through suitably-aligned storage of type unsigned char, as per P0137. Note also that Foo is a POD, with a trivial constructor. Questions: A. If I have misunderstood the standard, and there is any UB here, please kindly point it out (or alternatively confirm that there is no UB) B. Are the initialisations at A, B, C, D, E, F strictly necessary in light of the fact that the construction is trivial, and performs

How do I enable C++17 in Xcode for Mac OSX?

别等时光非礼了梦想. 提交于 2019-11-30 18:41:51
How do I enable C++17 in Xcode (9.4.1) on OSX High Sierra (10.13.5)? Steps to use C++17 in Xcode (9.4.1) on OSX High Sierra (10.13.5): Open existing or create a new C++ project in Xcode Click on the "show project navigator" button. It is located on the top-left section of Xcode window just below the minimize/maximize/close window buttons. It is the left-most icon and looks like a folder. Click on "Build Settings" and scroll down to find and expand the section "Apple LLVM 9.0 - Language - C++" Change the C++ Language Dialect combobox selection to "C++17 [-std=c++17]" Verification steps: Now

Can I use std::pair, but rename .first and .second member names?

∥☆過路亽.° 提交于 2019-11-30 17:54:48
A common design problem I run into, is that I bundle two variables together and then lose the ability to reference them in a meaningful way. std::pair<int,int> cords; cord.first = 0; //is .first the x or y coordinate? cord.second = 0; //is .second the x or y coordinate? I've considered writing basic structs instead, but then I lose a lot of the benefits that come along with std::pair : make_pair non-member overloaded operators swap get etc. Is there a way to rename or provide an alternative identifier for the first and second data members? I was hoping to leverage all of the the functions that

Conversion from std::string_view to std::string is implicit. What the hell did committe think?

我只是一个虾纸丫 提交于 2019-11-30 17:30:57
Seriously, whats't up. There is an implicit conversion from std::string to std::string_view and it's not considered unsafe. Even though this surely may cause a lot of dangling references if programmer is not careful. On the other hand, they have dismissed an implicit conversion from std::string_view to std::string using same argument but in completely opposite fashion: because programmer may be not careful . It's lovely that they have created a replacement for a raw const char* pointer while making it super confusing and stripped to the bone: Implicit const char* -> std::string : OK Implicit