c++17

Alternating Template Parameters Pack

孤人 提交于 2020-04-10 04:58:08
问题 How do I achieve a pack of alternating template parameters? Something like this: template< ( unsigned non_type, typename type )... > Where the usage must be my_class< 5U, float, 6U, std::string > I don't want to change the order nor do I want to have a wrapper around it as a pair during usage. Obviously, if it devolves into some sort of a pair in my own internal implementation, that's fine. 回答1: The thing to remember about templates is that they're not macros . They are not copying tokens

Alternating Template Parameters Pack

ε祈祈猫儿з 提交于 2020-04-10 04:55:26
问题 How do I achieve a pack of alternating template parameters? Something like this: template< ( unsigned non_type, typename type )... > Where the usage must be my_class< 5U, float, 6U, std::string > I don't want to change the order nor do I want to have a wrapper around it as a pair during usage. Obviously, if it devolves into some sort of a pair in my own internal implementation, that's fine. 回答1: The thing to remember about templates is that they're not macros . They are not copying tokens

Incomplete types as function parameters and return values

99封情书 提交于 2020-04-09 15:50:36
问题 The following code compiles successfully both with clang++ 5.0.0 and g++ 7.2 (with the -std=c++17 -Wall -Wextra -Werror -pedantic-errors -O0 compilation flags): struct Foo; struct Bar { Foo get() const; void set(Foo); }; struct Foo { }; Foo Bar::get() const { return {}; } void Bar::set(Foo) { } int main() { Bar bar{}; (void)bar.get(); bar.set(Foo{}); } Is it valid to use incomplete types as function parameters and return values? What does the C++ say on it? 回答1: In a function definition , you

Incomplete types as function parameters and return values

北战南征 提交于 2020-04-09 15:49:12
问题 The following code compiles successfully both with clang++ 5.0.0 and g++ 7.2 (with the -std=c++17 -Wall -Wextra -Werror -pedantic-errors -O0 compilation flags): struct Foo; struct Bar { Foo get() const; void set(Foo); }; struct Foo { }; Foo Bar::get() const { return {}; } void Bar::set(Foo) { } int main() { Bar bar{}; (void)bar.get(); bar.set(Foo{}); } Is it valid to use incomplete types as function parameters and return values? What does the C++ say on it? 回答1: In a function definition , you

Physx - linking problem with come functions (__imp_PxCreateBasePhysics referenced in function…)

会有一股神秘感。 提交于 2020-03-24 06:27:08
问题 I'm trying to implement PhysX into my game engine, but I have got some weird problems with linking the PhysX library. It always fails no matter what I do, but snippets from Nvidia works like a charm. I will try to describe what I did and I hope someone will find what I'm missing. First of all, I downloaded PhysX 4.1 from Github. Then I changed buildtools settings to those: <?xml version="1.0" encoding="utf-8"?> <preset name="vc15win64" comment="VC15 Win64 PhysX general settings"> <platform

QtCreator Cmake C++17 Features

假装没事ソ 提交于 2020-03-22 09:39:19
问题 So here I am, compiling my CMake-based C++ Projects in my terminal like there's not tomorrow with gcc-7.2.0 on Xubuntu 16.04 (via ppa) Everything works fine and the new features add considerable value to my codebase. However, trying to compile the very same project in qtcreator with the same compiler yields me errors like the following : error: expected ‘)’ before ‘;’ token if (auto event = events_.find(eventName); event == end(events_)) { ^ : error: ‘else’ without a previous ‘if’ } else { ^

How to assign “nothing” to std::optional<T>?

て烟熏妆下的殇ゞ 提交于 2020-03-21 11:32:16
问题 Reading about std::optional, I'm confused about what is the standard way to assign a value of something and nothing to an optional . I guess operator= would be the standard mechanism to assign a value to an optional. Seems to work. Does this imply a copy of the underlying object? What is the standard method to assign nothing ? I've seen x = {} (which makes no sense to me as {} is an empty block) and x = std::nullopt . 回答1: I wouldn't say there is one "standard" way to assign nothing to std:

Where exactly does my code not adhere to the specification of the key and value type?

此生再无相见时 提交于 2020-03-18 13:04:57
问题 Task Description interval_map<K,V> is a data structure that efficiently associates intervals of keys of type K with values of type V. Your task is to implement the assign member function of this data structure, which is outlined below. interval_map<K, V> is implemented on top of std::map . In case you are not entirely sure which functions std::map provides, what they do and which guarantees they provide, we provide an excerpt of the C++ standard here. (at the end) Each key-value-pair (k,v) in

Where exactly does my code not adhere to the specification of the key and value type?

房东的猫 提交于 2020-03-18 13:03:53
问题 Task Description interval_map<K,V> is a data structure that efficiently associates intervals of keys of type K with values of type V. Your task is to implement the assign member function of this data structure, which is outlined below. interval_map<K, V> is implemented on top of std::map . In case you are not entirely sure which functions std::map provides, what they do and which guarantees they provide, we provide an excerpt of the C++ standard here. (at the end) Each key-value-pair (k,v) in

Where exactly does my code not adhere to the specification of the key and value type?

南楼画角 提交于 2020-03-18 13:02:48
问题 Task Description interval_map<K,V> is a data structure that efficiently associates intervals of keys of type K with values of type V. Your task is to implement the assign member function of this data structure, which is outlined below. interval_map<K, V> is implemented on top of std::map . In case you are not entirely sure which functions std::map provides, what they do and which guarantees they provide, we provide an excerpt of the C++ standard here. (at the end) Each key-value-pair (k,v) in