GuillaumeDua / CppShelf

Collection of powerfuls - C++ Single-Header Libraries Files
https://guillaumedua.github.io/CppShelf/
MIT License
9 stars 1 forks source link

[mp] Fix count (and other algorithms) API, apply_t<trait, args...> #207

Open GuillaumeDua opened 5 months ago

GuillaumeDua commented 5 months ago

Or strict count: no pack specialization.

Motivation

using one = std::tuple<A, B, C>;
using two = std::tuple<B, C>;
count_v<A, one, two>; // what if we wanna check if "A" is either `one` or `two` ? (ambiguous)

Solution: plain + apply_t wrapper


template <typename T, typename ... ttps>
struct count : std::integral_constant<std::size_t, (std::size_t{0} + ... + std::size_t{std::is_same_v<T, ttps>})>{};
template <typename T, template <typename...> typename pack, typename ... ttps>
struct count<T, pack<ttps...>> : count<T, ttps...>{};
template <typename T, typename ... ttps>
constexpr std::size_t count_v = count<T, ttps...>::value;