Skip to content

Instantly share code, notes, and snippets.

@zoecarver
Last active May 3, 2019 03:33
Show Gist options
  • Save zoecarver/cdc4d24b7adac8c0f36edee156cc2f19 to your computer and use it in GitHub Desktop.
Save zoecarver/cdc4d24b7adac8c0f36edee156cc2f19 to your computer and use it in GitHub Desktop.
array<T, 0>
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