c++20

Can a non-type template parameter be of type “void*”?

怎甘沉沦 提交于 2019-11-28 07:14:11
问题 Yakk - Adam Nevraumont said: Non-type template parameters of type void* are not allowed in at least some versions of the standard. Is this true? If it is true, in which versions of the standard are non-type template parameters of type void* not allowed? (Note: as noted in a comment to answer another comment, this is about non-type template parameters , not template type arguments , which can be any valid type-id per [temp.arg.type], including void* . 回答1: TL;DR Template parameters of type

How do I use C++ modules in Clang?

牧云@^-^@ 提交于 2019-11-28 06:46:50
Modules are an alternative to #includes. Clang has a complete implementation for C++ . How would I go about if I wanted to use modules using Clang now? Using import std.io; in a C++ source file does not work (compile) yet, as the specification for modules (which includes syntax) isn't final. The Clang documentation states that, when passing the -fmodules flag, #includes will be rewritten to their appropriate imports. However, checking the preprocessor suggests otherwise (test.cpp only contains #include <stdio.h> and an empty main): $ clang++-3.5 -fmodules -E test.cpp -o test $ grep " printf "

What is the <=> operator in C++?

耗尽温柔 提交于 2019-11-27 16:57:23
While I was trying to learn about C++ operators, I stumbled upon a strange comparison operator on cppreference.com , * in a table that looked like this: "Well, if these are common operators in C++, I better learn them", I thought. But all my attempts to elucidate this mystery were unsuccessful. Even here, on Stack Overflow I had no luck in my search. Is there a connection between <=> and C++ ? And if there is, what does this operator do exactly? * In the meantime cppreference.com updated that page and now contains information about the <=> operator. This is called the three-way comparison

Why aren't ranges' algorithms compatible with std's iterators?

别等时光非礼了梦想. 提交于 2019-11-27 16:14:30
问题 #include <vector> #include <iostream> #include <range/v3/all.hpp> int main() { auto coll = std::vector{ 1, 2, 3 }; ranges::copy( coll, ranges::ostream_iterator<int>{ std::cout, ", " } ); // ok ranges::copy( coll, std::ostream_iterator<int>{ std::cout, ", " } ); // error } The issue is shown in the code above. I use ranges-v3-0.3.7. To me, the generic algorithm copy shouldn't care about the destination iterator type as long as it meets the requirements of output iterator. If so, why aren't

How to use source_location in a variadic template function?

我怕爱的太早我们不能终老 提交于 2019-11-27 10:44:57
问题 The C++20 feature std::source_location is used to capture information about the context in which a function is called. When I try to use it with a variadic template function, I encountered a problem: I can't see a place to put the source_location parameter. The following doesn't work because variadic parameters have to be at the end: // doesn't work template <typename... Args> void debug(Args&&... args, const std::source_location& loc = std::source_location::current()); The following doesn't

Will specialization of function templates in std for program-defined types no longer be allowed in C++20?

安稳与你 提交于 2019-11-27 02:33:33
问题 Quote from cppreference.com: Adding template specializations It is allowed to add template specializations for any standard library |class (since C++20)| template to the namespace std only if the declaration depends on at least one program-defined type and the specialization satisfies all requirements for the original template, except where such specializations are prohibited. Does it mean, that starting from C++20, adding specializations of function templates to the std namespace for user

How do I use C++ modules in Clang?

淺唱寂寞╮ 提交于 2019-11-27 01:35:42
问题 Modules are an alternative to #includes. Clang has a complete implementation for C++. How would I go about if I wanted to use modules using Clang now? Using import std.io; in a C++ source file does not work (compile) yet, as the specification for modules (which includes syntax) isn't final. The Clang documentation states that, when passing the -fmodules flag, #includes will be rewritten to their appropriate imports. However, checking the preprocessor suggests otherwise (test.cpp only contains

Why does C++11 have implicit moves for value parameters, but not for rvalue parameters?

自闭症网瘾萝莉.ら 提交于 2019-11-27 01:06:33
问题 In C++11, value parameters (and other values) enjoy implicit move when returned: A func(A a) { return a; // uses A::A(A&&) if it exists } At least in MSVC 2010, rvalue reference parameters need std::move : A func(A && a) { return a; // uses A::A(A const&) even if A::A(A&&) exists } I would imagine that inside functions, an rvalue reference and a value behave similar, with the only difference that in case of values, the function itself is responsible for destruction, while for rvalue

Does constraint subsumption only apply to concepts?

只愿长相守 提交于 2019-11-26 20:37:36
问题 Consider this example: template <typename T> inline constexpr bool C1 = true; template <typename T> inline constexpr bool C2 = true; template <typename T> requires C1<T> && C2<T> constexpr int foo() { return 0; } template <typename T> requires C1<T> constexpr int foo() { return 1; } constexpr int bar() { return foo<int>(); } Is the call foo<int>() ambiguous, or does the constraint C1<T> && C2<T> subsume C1<T> ? 回答1: Yes. Only concepts can be subsumed. The call to foo<int> is ambiguous because

What is the <=> operator in C++?

自古美人都是妖i 提交于 2019-11-26 18:47:52
问题 While I was trying to learn about C++ operators, I stumbled upon a strange comparison operator on cppreference.com, * in a table that looked like this: "Well, if these are common operators in C++, I better learn them", I thought. But all my attempts to elucidate this mystery were unsuccessful. Even here, on Stack Overflow I had no luck in my search. Is there a connection between <=> and C++ ? And if there is, what does this operator do exactly? * In the meantime cppreference.com updated that