c++17

inline static member variable

别来无恙 提交于 2019-12-12 08:35:02
问题 struct sa { struct sb { int a = 123;}; inline static sb b; }; The above code generates an error: main.cpp:25:20: error: default member initializer for ‘sa::sb::a’ required before the end of its enclosing class inline static sb b; ^ main.cpp:24:21: note: defined here struct sb { int a = 123;}; ^~~~~~ Removing the inline keyword or the default member initializer works. But just from the output, I don't understand why this usage is wrong. 回答1: I think this code is correct and should be accepted;

Why does GCC not seem to have the filesystem standard library?

▼魔方 西西 提交于 2019-12-12 08:29:02
问题 i'm facing a problem with filesystem library, it should be included in c++17 compiler, after 2 days i tried to install gcc-7.0.2 in raspberry pi but it didn't work, it couldn't recognize the command gcc-7 or g++-7 or even -std=c++17 so i had to install g++-6 and gcc-6 using apt-get install anyway, after installing the 6 version the compiler include c++17. i'm using codeblocks as IDE, i had to add a new compiler and add the option -std=c++17 to enable it,but in the main code when i include the

When do I use node_type with std::map::insert?

梦想的初衷 提交于 2019-12-12 08:25:52
问题 I'm accustomed to the existing interface of std::map . Inserting elements returns a bool describing successful insertion, as well the iterator as to where the inserted element would be. template< class P > std::pair<iterator,bool> insert( P&& value ); //(since C++11) C++17 adds what looks to be a similar call, but with different type names: insert_return_type insert(node_type&& nh); //(since C++17) I tried looking up what a node_type is, but it is primarily unspecified: template</*unspecified

What's the purpose of layout-compatible types?

我与影子孤独终老i 提交于 2019-12-12 08:02:41
问题 The standard defines when two types are layout-compatible . But, I don't see anywhere in the standard what the consequences are when two types are layout-compatible . It seems that layout-compatible is a definition which is not used anywhere. What is the purpose of layout-compatible ? Note: Supposedly, it could mean that the types have the same layout ( offsetof is the same for each corresponding member), so for example, for trivially copyable types, underlying bytes can be copied between

Is instantiating a class template with an incomplete type ill-formed, if the type is defined afterwards?

偶尔善良 提交于 2019-12-12 07:50:05
问题 This code is surely ill-formed, because Foo is specialized after an instantiation point: template <typename T> struct Foo { int a; }; Foo<int> x = { 42 }; template <> struct Foo<int> { const char *a; }; Foo<int> x = { "bar" }; It is ill formed because of the part of the standard I've put emphasis: A specialization for a function template, a member function template, or of a member function or static data member of a class template may have multiple points of instantiations within a

GCC7 ARMv7-a compilation error in standard headers

血红的双手。 提交于 2019-12-11 18:41:10
问题 I am trying to compile my C++1z application for the ARMv7-a architecture using GCC7. I tested and have the application working in Ubuntu 16.04 (x86_64), but when I try compiling it on the ARM device (Ubuntu 14.04) I end up with compilation errors in the standard headers. One example of the errors is: In file included from /usr/include/c++/7/bits/ios_base.h:46:0, from /usr/include/c++/7/ios:42, from /usr/include/c++/7/istream:38, from /usr/include/c++/7/sstream:38, from /usr/include/c++/7

Using auto with variadic templates that generates a tuple

佐手、 提交于 2019-12-11 17:06:00
问题 I have been working on this for some time and I found this Q/A as a good answer into how I can store a tuple. Now I'm trying to use a function template that will generate this class and the auto key word to generate instances of this object. I'm not getting any compiler errors; yet it isn't generating any data and I can not figure out where I'm going wrong, however, my ostream<<() is generating compiler errors complaining about std::get Here is my class and a few ways of how I'm trying to use

Is this an elegant way to overload a static member function that provides the same interface as a non static member function?

本秂侑毒 提交于 2019-12-11 15:59:59
问题 Consider the following non class template that has a template variable and uses template aliasing and auto type deduction. template<typename T> using Type = T; using TypeA = Type<int>; using TypeB = Type<double>; class Foo { private: template<typename T> static Type<T> type_; public: template<typename T> explicit Foo( Type<T> type ) { type_<T> = type; } // non static member template<typename T> auto bar() { return type_<T>; } // static member template<typename T> static auto bar(T _x_ = 0) {

std::isgraph asserts, how to fix?

 ̄綄美尐妖づ 提交于 2019-12-11 15:57:02
问题 Im getting the following assert when calling std::isgraph: _ASSERTE(c >= -1 && c <= 255); It's a unicode built on Windows platform, but the locale is reported as "c". What should I set the locale to in order to support unicode ? 回答1: Nothing. std::isgraph has nothing to do with Unicode. In particular, it cannot support any character value out of the range you've mentioned. You could pass it individual bytes of a [say, UTF-8] codepoint, sure, but that wouldn't tell you anything. It's simply

avoid writing the same repetitive type-checking code with std::any

独自空忆成欢 提交于 2019-12-11 15:42:38
问题 I want to use std::any in my program but I find myself writing a lot of conditional statements like this: if (anything.type() == typeid(short)) { auto s = std::any_cast<short>(anything); } else if (anything.type() == typeid(int)) { auto i = std::any_cast<int>(anything); } else if (anything.type() == typeid(long)) { auto l = std::any_cast<long>(anything); } else if (anything.type() == typeid(double)) { auto d = std::any_cast<double>(anything); } else if (anything.type() == typeid(bool)) { auto