How to filter duplicate types from tuple C++

前端 未结 4 1985
遇见更好的自我
遇见更好的自我 2020-12-17 18:36

How does one filter duplicate types from a tuple?

For example:

using Tuple = std::tuple
usi         


        
4条回答
  •  生来不讨喜
    2020-12-17 19:03

    If you have access to Boost, then this can be done directly using boost::mp11::mp_unique.

    For example:

    {
      using not_unique = std::tuple;
      using filtered = boost::mp11::mp_unique;
      static_assert(std::is_same_v, filtered>);
    }
    {
      using already_unique = std::tuple;
      using filtered = boost::mp11::mp_unique;
      static_assert(std::is_same_v, filtered>);
    }
    

    Live example

提交回复
热议问题