#include namespace details { template struct occurance_count; template struct occurance_count { constexpr static int const value { (std::is_same_v ? 1 : 0) + occurance_count::value }; }; template struct occurance_count { constexpr static int const value { 0 }; }; } template struct most_common; template struct most_common { private: constexpr static int const current { details::occurance_count::value }; constexpr static int const rest { most_common::value }; public: constexpr static int const value { (current >= rest ? current : rest) }; using type = std::conditional_t< (current >= rest), T, typename most_common::type >; }; template struct most_common { constexpr static int const value { 1 }; using type = T; }; template using most_common_t = typename most_common::type; int main() { static_assert( std::is_same_v::type, int> ); static_assert( most_common::value == 1 ); static_assert( std::is_same_v::type, int> ); static_assert( most_common::value == 2 ); static_assert( std::is_same_v::type, int> ); static_assert( most_common::value == 2 ); static_assert( std::is_same_v::type, float> ); static_assert( most_common::value == 2 ); static_assert( std::is_same_v::type, int> ); static_assert( most_common::value == 3 ); }