c++17

What is the point of the UTF-8 character literals proposed for C++17?

允我心安 提交于 2019-12-19 05:05:06
问题 What exactly is the point of these as proposed by N4267 ? Their only function seems to be to prevent extended ASCII characters or partial UTF-8 code points from being specified. They still store in a fixed-width 8-bit char (which, as I understand it, is the correct and best way to handle UTF-8 anyway for almost all use cases), so they don't support non-ASCII characters at all. What is going on? (Actually I'm not entirely sure I understand the need for UTF-8 string literals either. I guess it

clang 3.6 fold expression left/right

孤街醉人 提交于 2019-12-19 02:03:28
问题 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 回答1: n4191 was revised by

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

流过昼夜 提交于 2019-12-18 19:06:17
问题 How do I enable C++17 in Xcode (9.4.1) on OSX High Sierra (10.13.5)? 回答1: 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 -

Why does for_each return function by move

﹥>﹥吖頭↗ 提交于 2019-12-18 15:53:18
问题 I was reading the documentation for std::for_each here http://en.cppreference.com/w/cpp/algorithm/for_each and saw that the return value is std::move(f) Why does the standard enforce moving the input parameter in the return value? Won't it be moved by default anyway, since the input parameter is passed by value? This leads me to a couple of followups, when you compile the following code Something function(Something something) { return something; } The return statement is a move on my system

Overloading structs with template call operator and generic lambdas - gcc vs clang

若如初见. 提交于 2019-12-18 15:08:19
问题 I have discovered a code snippet that compiles and works properly in clang++ 4 (and trunk) but fails to compile in g++ 7 (and trunk) . Let's assume I have the following struct types: struct a { void foo() { } }; struct b { void bar() { } }; struct c { void bar() { } }; I want to create an overload set out of lambdas which handles a explicitly, while b and c are "caught" with a generic lambda using an auto parameter: auto ol = overload([](a x) { x.foo(); }, [](auto x){ x.bar(); }) When I

Why does moving std::optional not reset state

一笑奈何 提交于 2019-12-18 14:06:08
问题 I was rather surprised to learn that the move constructor (and assignment for that matter) of std::optional does not reset the optional moved from, as can be seen in [19.6.3.1/7] which states "bool(rhs) is unchanged." This can also be seen by the following code: #include <ios> #include <iostream> #include <optional> #include <utility> int main() { std::optional<int> foo{ 0 }; std::optional<int> bar{ std::move(foo) }; std::cout << std::boolalpha << foo.has_value() << '\n' // true << bar.has

Whats is proper version of llvm/clang/xcode?

旧巷老猫 提交于 2019-12-18 13:54:10
问题 This gist mentions that xcode 9 published with 'Apple LLVM version 9.0.0 (clang-900.0.38)', but the last version of llvm in llvm.org is LLVM 5.0.0. What is the relation between them? 回答1: Apple's Xcode ship with LLVM, but it is not the open source version. For example, some clang extra tool won't be installed to you Mac. So at least, Apple has modify CMakeLists.txt . You can read the CMakeLists.txt or Makefile in apple open source. This is only a suggestion, maybe is not helpful. Another:

Should this code fail to compile in C++17?

两盒软妹~` 提交于 2019-12-18 13:52:15
问题 I was updating a project to use C++17 and found a few instances where code that followed this pattern was causing a compile error on recent versions of clang: #include <boost/variant.hpp> struct vis : public boost::static_visitor<void> { void operator()(int) const { } }; int main() { boost::variant<int> v = 0; boost::apply_visitor(vis{}, v); } Using clang v8.0 in C++17 mode, this fails with the following error: <source>:11:30: error: temporary of type 'boost::static_visitor<void>' has

How to perform tuple arithmetic in C++ (c++11/c++17)?

£可爱£侵袭症+ 提交于 2019-12-18 13:33:43
问题 I'm trying to write template functions/operators such as + for doing arithmetic operations between two tuples of the same type. For example, for std::tuple<int,double> t = std::make_tuple(1,2); I'd like to do auto t1 = t + t; The logic is simple: to do the arithmetic element-wise. But I can't figure out how to make this work in c++ template programming (c++11/17). My code below doesn't compile with g++ -std=c++11 tuple_arith.cpp . In particular, I can't figure out the right way of getting the

reinterpret_cast, char*, and undefined behavior

☆樱花仙子☆ 提交于 2019-12-18 13:06:48
问题 What are the cases where reinterpret_cast ing a char* (or char[N] ) is undefined behavior, and when is it defined behavior? What is the rule of thumb I should be using to answer this question? As we learned from this question, the following is undefined behavior: alignas(int) char data[sizeof(int)]; int *myInt = new (data) int; // OK *myInt = 34; // OK int i = *reinterpret_cast<int*>(data); // <== UB! have to use std::launder But at what point can we do a reinterpret_cast on a char array and