Category : aggregate-initialization

#include <iostream> struct U { template<typename T> operator T(); }; template<unsigned I> struct X : X<I – 1> {}; template<> struct X<0> {}; template<typename T> constexpr auto f(X<4>) -> decltype(T(U{}, U{}, U{}, U{}), 0u) { return 4u; } template<typename T> constexpr auto f(X<3>) -> decltype(T(U{}, U{}, U{}), 0u) { return 3u; } template<typename T> constexpr ..

Read more

struct BasePluginInfo { bool bHasGui, bIsSynth; char cType; std::string sCategory, sSdkVersion, sVendor, sVersion; }; struct PluginClassInfo { std::string sName, sUid; std::vector<std::string> vsParamNames; }; struct ShellPluginInfo : BasePluginInfo { std::vector<PluginClassInfo> vciClasses; }; When I do ShellPluginInfo { .bHasGui = true }; The compiler complains that ShellPluginInfo has no field ‘bHasGui’. However this works: ShellPluginInfo info; info.bHasGui ..

Read more

Here’s the setup to illustrate the problem. template <typename T> struct opt { const char* name; T x; template <typename X> opt(const char* name, X&& x) : name(name), x(std::forward<X>(x)) { } }; template <typename T> opt(const char*, T&&) -> opt< some_type_transformation<T> >; template <typename… T> void function(opt<T>&&… opts) { // do something with the passed ..

Read more

C++20 introduced support for designated initializers. In g++ with -std=c++17, one can use designated initializers and as long as you don’t leave any out, it will compile without any errors or warnings: struct Foo { int a; float b; }; Foo f { .a = 7, .b = 42.1f, }; Yet if I enable -Wpedantic ..

Read more