c++17

Compiler which can compile c++17 lambda inheritance with parameter pack

爱⌒轻易说出口 提交于 2019-12-23 13:04:44
问题 I read about the using function declaration and I wanted to compile the last example. This is : #include <iostream> template <typename... Ts> struct Overloader : Ts... { using Ts::operator()...; // exposes operator() from every base }; template <typename... T> constexpr auto make_overloader(T&&... t) { return Overloader<T...>{std::forward<T>(t)...}; } int main() { auto o = make_overloader([] (auto const& a) {std::cout << a;}, [] (float f) {std::cout << 13 << f;}); } Even if I already know and

byte and ambiguous symbol due to using declarations?

佐手、 提交于 2019-12-23 12:25:50
问题 We are a C++ library . For years we had typedef unsigned char byte; in the global namespace. User programs and other libraries provided compatible definitions of byte , so there were no problems. C++17 added std::byte and changed semantics of a byte. Now we need to be more hygienic by avoid global namespace pollution; and we need to insulate ourselves from std::byte . Our change is to move our byte into our namespace. We are witnessing an unexpected failure as we test the impact of changes.

C++ Concepts: Can I define a concept that is itself a template?

岁酱吖の 提交于 2019-12-23 12:23:18
问题 Sorry if the question isn't too clear. I'm not sure the best way to phrase it (feel free to edit!). I think an example would be the most clear: I am attempting to define a Monad concept based off of the Haskell definition. The bind operator ( >>= ) requires that a Monad of type A can be bound to a function that takes an A and returns a Monad of type B . I can define A in terms of a value_type typedef but how do I define type B in my concept? template <typename M> concept bool Monad() { return

Compiler for C++ 17 [closed]

梦想的初衷 提交于 2019-12-23 09:58:01
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Is there any online place where I can run a C++17 code, as I want to learn the new features of C++ 17. I tried running it on inbuilt Coliru compiler GCC 6.1 C++ 17. But it is unfortunately not compiling. Is the compiler for C++17 not yet out, I searched it everywhere on Internet? 回答1: wandbox supports g++ 7.0

Using incomplete type in a member function of a class template

烈酒焚心 提交于 2019-12-23 09:09:27
问题 GCC (8.3, 9.1), Clang (7, 8) and MSVC (19.20) differ is their ability to compile this code: struct C; template<typename T> struct S { void foo() { // C2 c; C c; } }; class C {}; int main() { S<int> s; s.foo(); return 0; } GCC and MSVC accept it, whereas Clang rejects it. Clang rejects it even if I make foo itself a template and/or do not call it at all. My understanding is that foo is not instantiated unless it is called, and it is instantiated at the point where it is called. At that point C

Forwarding template taking precedence over overload

試著忘記壹切 提交于 2019-12-23 09:03:56
问题 I thought that a non-template would always take precedence over a template, if the arguments match up just as well. But: template <typename... Args> void Trace(Args&&... args) { throw "what the frak"; } void Trace(const int&) {} int main() { Trace(42); } This throws unless I make the non-template Trace(int) or Trace(int&&) , i.e. not taking a const ref. It's kind of annoying because I want to provide a different implementation for specific argument types where the real implementation of the

I just can not understand DR 712

落爺英雄遲暮 提交于 2019-12-23 07:45:51
问题 DR 712 was responsible for the change in the wording of [basic.def.odr]/2 in C++11 to the current wording today, in [basic.def.odr]2 and 3. But I'm still trying to understand the reason for the change, as stated in the DR, as follows: 712. Are integer constant operands of a conditional-expression “used?” In describing static data members initialized inside the class definition, 9.2.3.2 [class.static.data] paragraph 3 says, The member shall still be defined in a namespace scope if it is used

Why is this expression not a constant expression?

安稳与你 提交于 2019-12-23 07:01:28
问题 The expression b in this code shall be a core constant expression int main() { constexpr int a = 10; const int &b = a; constexpr int c = b; // here return 0; } since the standard says (8.20, paragraph 2 [expr.const] in n4700) An expression e is a core constant expression unless the evaluation of e would evaluate one of the following expressions: ... an lvalue-to-rvalue conversion (7.1) unless it is applied to ... a non-volatile glvalue that refers to a non-volatile object defined with

Significance of trivial destruction

岁酱吖の 提交于 2019-12-23 06:57:14
问题 In C++17, the new std::optional mandates that it be trivially destructible if T is trivially destructible in [optional.object.dtor]: ~optional(); 1 Effects : If is_trivially_destructible_v<T> != true and *this contains a value, calls val->T::~T() . 2 Remarks : If is_trivially_destructible_v<T> == true then this destructor shall be a trivial destructor. So this potential implementation fragment would be non-conforming to the standard: template <class T> struct wrong_optional { union { T value;

Update Visual Studio Code error squiggles to C++ 17

☆樱花仙子☆ 提交于 2019-12-23 03:58:10
问题 In Visual Studio Code, I created the following file: #include <iostream> using namespace std; template <auto value> void g() { // requires c++17 cout << "g " << value << endl; } int main() { g<10>(); // deduces int; requires c++17 } In the editor, the "g" in the before-last line has a red underline, and the error message says: no instance of function template "g" matches the argument list template<<error-type> value> void g() I guess this is because the code uses a new feature introduced in C