c++17

Trailing class template arguments not deduced

梦想的初衷 提交于 2019-11-29 06:02:00
The code below fails to compile with gcc 7.1.0, which complains about providing the wrong number of template arguments in the second line of main. This version of GCC is supposed to implement template argument deduction of class templates. I think the compiler should be able to deduce the class template argument T2 for Bar, which means that I shouldn't have to explicitly specify both arguments ( Bar<int, int> ) given paragraph 17.8.1.3 of the C++17 draft which says, "Trailing template arguments that can be deduced (17.8.2) or obtained from default template-arguments may be omitted from the

C++ standard: do namespace-scoped constexpr variables have internal linkage?

给你一囗甜甜゛ 提交于 2019-11-29 05:44:58
Imagine we have a header foo.h containing the following: #ifndef FOO_H_ #define FOO_H_ namespace foo { constexpr std::string_view kSomeString = "blah"; } #endif // FOO_H_ Is foo::kSomeString guaranteed to have internal linkage in any translation unit that includes foo.h ? Does this vary between C++11 and C++17? In the draft standard [basic.link]/3 says A name having namespace scope has internal linkage if it is the name of [...] a non-inline variable of non-volatile const-qualified type that is neither explicitly declared extern nor previously declared to have external linkage [...] But I don

Are inline variables unique across boundaries?

ぐ巨炮叔叔 提交于 2019-11-29 05:34:39
This is a follow up of this question . As mentioned in the comments to the answer: An inline variable has the property that - It has the same address in every translation unit . [...] Usually you achieved that by defining the variable in a cpp file, but with the inline specifier you can just declare/define your variables in a header file and every translation unit using this inline variable uses exactly the same object. Moreover, from the answer itself: While the language does not guarantee (or even mention) what happens when you use this new feature across shared libraries boundaries, it does

Why is std::iterator deprecated?

巧了我就是萌 提交于 2019-11-29 05:24:45
Template class std::iterator is set to be deprecated in C++17. Why so? It has been a handy way to make sure std::iterator_traits works, especially if you can make use of the default template arguments. Is there some other way of doing it in C++17? Barry From the proposal that suggested its deprecation : As an aid to writing iterator classes, the original standard library supplied the iterator class template to automate the declaration of the five typedefs expected of every iterator by iterator_traits. This was then used in the library itself, for instance in the specification of std::ostream

Can we refer to member variables in a noexcept specification?

跟風遠走 提交于 2019-11-29 04:06:59
Please consider the following code snippet: template<class Tuple> class vector { public: typename Tuple::size_type size() const noexcept(noexcept(m_elements.size())) { return m_elements.size(); } private: Tuple m_elements; }; class tuple { public: using size_type = std::size_t; size_type size() const { return 0; } size_type size() noexcept { return 0; } }; int main() { vector<tuple> x; static_assert(noexcept(x.size()), "x.size() might throw"); return 0; } Is the use of the member variable m_elements inside the noexcept specifier legal? GCC 5.2 (C++17) yields the compiler error m_elements was

Is it possible to know when is constexpr really a constexpr?

南楼画角 提交于 2019-11-29 03:07:10
Since the extended versions of constexpr (I think from C++14) you can declare constexpr functions that could be used as "real" constexpr, that is, the code executed at compile time or can behave as inline functions. So when can have this program: #include <iostream> constexpr int foo(const int s) { return s + 4; } int main() { std::cout << foo(3) << std::endl; const int bar = 3; std::cout << foo(bar) << std::endl; constexpr int a = 3; std::cout << foo(a) << std::endl; return 0; } Of course, the result is: 7 7 7 so far so good. So my question is: is there a way (possibly standard) to know in

Undefined behaviour in repeated use of prefix ++ operator

。_饼干妹妹 提交于 2019-11-29 02:32:03
问题 I read this answer about undefined behaviour, where I saw following statement: ++++++i; // UB, parsed as (++(++(++i))) I don't think it is undefined behaviour. I have a doubt, Is it really UB in C++? If yes, then How? Also, I made program and compiled using g++ prog.cpp -Wall -Wextra -std=gnu++1z -pedantic command, it's working fine without any warning. It's give an expected output. #include <iostream> using namespace std; int main() { int i = 0; cout<<++++++i<<endl; } 回答1: In C++03 it is

How to enable C++17 on Mac?

你说的曾经没有我的故事 提交于 2019-11-29 02:28:31
问题 I am able to update gcc on Linux to get -std=c++17 but cannot do the same on Mac. Is there a version of Clang I can update to or some other alternative to get C++17 on my Mac? Please help. Thanks. 回答1: On my 10.11 El Capitan, Xcode 7.3.1, clang has been updated to: Apple LLVM version 7.3.0 (clang-703.0.31) which is almost equivalent to llvm version 3.8. clang++ hasn't -std=c++17 option, but -std=c++1z , working well at present, though only supporting some features of C++1z. For gcc, you can

How to assert that a constexpr if else clause never happen?

▼魔方 西西 提交于 2019-11-29 02:16:25
问题 I want to raise a compile time error when non of the constexpr if conditions is true eg: if constexpr(condition1){ ... } else if constexpr (condition2) { .... } else if constexpr (condition3) { .... } else { // I want the else clause never taken. But I heard the code below is not allowed static_assert(false); } // I'd rather not repeat the conditions again like this: static_assert(condition1 || condition2 || condition3); 回答1: You have to make the discarded statement dependent of the template

What is the reason for `std::result_of` deprecated in C++17?

冷暖自知 提交于 2019-11-29 01:47:40
I saw std::result_of is being deprecated in C++17. What is the reason for std::result_of deprecated in C++17? Also I would like to know the difference between std::result_of and std::invoke_result . T.C. already provided the obvious link, but perhaps the most horrific reason bears repeating: result_of involved forming the type F(Arg1, Arg2, ...) not for a function of those types returning F but for a function of type F accepting those types. (After all, the return type is the result of, well, result_of , not the input!) Aside from the adjustments associated with forming the function type, the