Код: Выделить всё
#include
#include
struct Bitset
{
std::bitset defined_ids;
template
bool ContainsAnyOf(property_ids ... ids) const
{
using bitset_type_t = decltype(defined_ids);
auto getBitset = [&] () consteval -> bitset_type_t
{
bitset_type_t result;
//(result.set(ids), ...); // THIS LINE FAILS
//error: constexpr variable 'compare_bitset' must be initialized by a constant expression
return result;
};
constexpr bitset_type_t zero_bitset;
constexpr bitset_type_t compare_bitset = getBitset();
return (compare_bitset & defined_ids) != zero_bitset;
}
};
int main()
{
constexpr Bitset bitset;
bitset.ContainsAnyOf(1, 2, 3, 4);
return 0;
}
< /code>
Вот ссылка Godbolt на вышеупомянутое. GCC - единственный, что компилируется, даже если я расстроен метод .set Call: < /p>
#include
#include
struct Bitset
{
std::bitset defined_ids;
template
bool ContainsAnyOf() const
{
using bitset_type_t = decltype(defined_ids);
auto getBitset = [] () consteval -> bitset_type_t
{
bitset_type_t result;
//(result.set(ids), ...);
// Clang doesn't compile this at all
// GCC and MSVC compile even with this line uncommented.
return result;
};
constexpr bitset_type_t zero_bitset;
constexpr bitset_type_t compare_bitset = getBitset.template operator()();
return (compare_bitset & defined_ids) != zero_bitset;
}
};
int main()
{
constexpr Bitset bitset;
bitset.ContainsAnyOf();
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... mpile-time