Last active
May 3, 2019 03:33
-
-
Save zoecarver/cdc4d24b7adac8c0f36edee156cc2f19 to your computer and use it in GitHub Desktop.
array<T, 0>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> | |
struct Container | |
{ | |
union wrapper { | |
constexpr wrapper(): b() {} | |
~wrapper() = default; | |
bool b; | |
T t; | |
} w; | |
Container(int) { } | |
}; | |
template<class T> | |
class Foo | |
{ | |
public: | |
const Container<T> c { 0 }; | |
constexpr const T* data() const { | |
return &c.w.t; | |
} | |
}; | |
inline constexpr bool member_is_consexpr(Foo<int> const& foo) | |
{ | |
return foo.data() && true; | |
} | |
int main() | |
{ | |
const Foo<int> foo {}; | |
const Foo<int> bar {{}}; // error | |
static_assert(member_is_consexpr(foo)); // works | |
static_assert(std::is_aggregate<Foo<int>>::value); // works | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment