You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Did u test it on MSVC back then when you created this since now it does not work. I checked that COUNTER works just fine but the fameta::counter can't get past the start index with any given number.
MSVC:
LLVM Clang:
Code for that:
The text was updated successfully, but these errors were encountered:
I've immplemented same counter, but compatible with msvc.
It uses same method as unconstexpr-cpp20, but works in most of c++17 compilers (gcc7+, clang5+, all c++17 msvc versions)
template <typename T>
struct Counter
{
template <int I>
struct Flag
{
template<typename F>
friend constexpr bool Check(Flag, F);
};
template<int I>
struct MarkFlag
{
template<typename F>
friend constexpr bool Check(Flag<I>, F) { return false; }
};
template <int I, typename F, bool = Check(Flag<I>{}, F{})>
constexpr static bool IsMarked(int) { return true; }
template <int I, typename F>
constexpr static bool IsMarked(float) { return false; }
template <typename F> struct WrapT{};
template<typename F, int I = 0>
constexpr static int Inc()
{
if constexpr (IsMarked<I, WrapT<F>>(0)) return Inc<F, I+1>();
else return I + sizeof(MarkFlag<I>) - 1;
};
};
// use lambda as unique type
#define CounterInc(T) []{constexpr auto unq = []{}; return Counter<T>::Inc<decltype(unq)>();}()
This does not generate warnings for non-template friend injection
I using lambda for unique identifier, this targets c++17. Maybe this will work on pre-c++17 compilers with unique types or line constants if replace Inc() by SFINAE
Main difference is passing unique type to friend injection template and splitting flag check from increment
I have not implemented binary search, but hope it's possible
Apparently this doesn't work on MSVC.
Did u test it on MSVC back then when you created this since now it does not work. I checked that COUNTER works just fine but the fameta::counter can't get past the start index with any given number.
MSVC:
LLVM Clang:
Code for that:
The text was updated successfully, but these errors were encountered: