c++17

Is TR2 Going to be Released in C++17?

試著忘記壹切 提交于 2019-11-28 04:41:54
问题 There is lots of sweet stuff in TR2. Is that going to be in C++17? I understand that TR1 was completed in 2005 and had to wait until C++11 to be standardized. But I also understand that TR2 is already complete? My link to C++17 doesn't mention anything about TR2, but I am hoping... 回答1: Maybe. The point of TR (and now technical specifications) is to allow something to mature independent of the standard iteration process. They can publish a TS, see how it works, see if there are any problems

function implementation with enable_if outside of class definition

[亡魂溺海] 提交于 2019-11-28 03:54:00
问题 So basically, I have a very basic generic class for now, currently testing the type_traits header. I am currently trying to make a function to work with certain types i.e arithmetic ones for now. #include <type_traits> template <typename T> class Test { public: template <typename U = T> typename std::enable_if<std::is_arithmetic<U>::value>::type print(); }; The function works perfectly and for arithmetic types only. But I like to keep my classes tidy and only have them have prototypes, while

Can std::is_invocable be emulated within C++11?

北战南征 提交于 2019-11-28 03:28:47
问题 I'd like to use std::is_invocable, however we are using c++11 standard, while is_invocable is available only from c++17. Is there any way to emulate the functionality using c++11? Thank you 回答1: You can try this implementation:) Taken from boost C++ libraries. I've tested it with VS2017 with standard C++14. template <typename F, typename... Args> struct is_invocable : std::is_constructible< std::function<void(Args ...)>, std::reference_wrapper<typename std::remove_reference<F>::type> > { };

C++17 structured binding that also includes an existing variable

岁酱吖の 提交于 2019-11-28 03:23:43
问题 This SO answer lists some shortcomings of C++17 decomposition declarations (the feature formerly known as "structured binding"). For example, you can't give explicit types to the new variables, and so on. But one big shortcoming I'm running into isn't mentioned there, so I wonder if there's a known workaround that I'm just not thinking of. Consider this JSON-parsing code (which may contain other bugs; please ignore them for the purposes of this question): using Value = std::any; using String

Using std::string_view with api, what expects null terminated string

China☆狼群 提交于 2019-11-28 03:21:58
问题 I have a method that takes std::string_view and uses function, which takes null terminated string as parameter. For example: void stringFunc(std::experimental::string_view str) { some_c_library_func(/* Expects null terminated string */); } The question is, what is the proper way to handle this situation? Is str.to_string().c_str() the only option? And I really want to use std::string_view in this method, because I pass different types of strings in it. 回答1: You cannot alter a string through

std::filesystem::directory_iterator linker issue (C++17) [duplicate]

我与影子孤独终老i 提交于 2019-11-28 03:15:23
问题 This question already has answers here : Link errors using <filesystem> members in C++17 (2 answers) Closed last year . I'm having an issue with my C++ built when trying to use the std::filesystem::directory_iterator from the C++17 standard. Here is the code: std::vector<std::string> IO::getDirectoryList(std::filesystem::path& dirPath) { std::vector<std::string> files; for (auto& file : std::filesystem::directory_iterator(".")) { files.push_back(file.path()); } return files; } I get the

How can I make this variadic template code shorter using features from C++14 and C++1z?

情到浓时终转凉″ 提交于 2019-11-28 03:08:23
问题 This is a code snippet that I am going to use in order to check whether the variadic template types are unique: template <typename...> struct is_one_of; template <typename F> struct is_one_of<F> { static constexpr bool value = false; }; template <typename F, typename S, typename... T> struct is_one_of<F, S, T...> { static constexpr bool value = std::is_same<F, S>::value || is_one_of<F, T...>::value; }; template <typename...> struct is_unique; template <> struct is_unique<> { static constexpr

Get index by type in std::variant

半世苍凉 提交于 2019-11-28 02:59:40
问题 Is there a utility in the standard library to get the index of a given type in std::variant ? Or should I make one for myself? That is, I want to get the index of B in std::variant<A, B, C> and have that return 1 . There is std::variant_alternative for the opposite operation. Of course, there could be many same types on std::variant 's list, so this operation is not a bijection, but it isn't a problem for me (I can have first occurrence of type on list, or unique types on std::variant list).

What made i = i++ + 1; legal in C++17?

谁说胖子不能爱 提交于 2019-11-28 02:48:34
Before you start yelling undefined behaviour, this is explicitly listed in N4659 (C++17) i = i++ + 1; // the value of i is incremented Yet in N3337 (C++11) i = i++ + 1; // the behavior is undefined What changed? From what I can gather, from [N4659 basic.exec] Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. [...] The value computations of the operands of an operator are sequenced before the value computation of the result of the operator. If a side effect on a memory location is unsequenced relative to either

Undefined reference error for static constexpr member

*爱你&永不变心* 提交于 2019-11-28 02:37:25
问题 Consider this code: #include <vector> struct A { static constexpr int kDefaultValue = -1; std::vector<int> v; A(int n): v(n, A::kDefaultValue) {} }; int main() { A(10); return 0; } It fails to link (llvm clang, gcc 4.9, both on OS X): Undefined symbols for architecture x86_64: "A::kDefaultValue", referenced from: A::(int) in main.cpp.o ld: symbol(s) not found for architecture x86_64 The question is what's wrong with it? It can be fixed by static_cast -ing A::kDefaultValue to int . Or by