types: add the convert trait

This unconditionally replaces the first argument with the second.

It can be useful when dealing with parameter packs.
This commit is contained in:
Danny Robson 2020-02-07 10:15:43 +11:00
parent 0ded941de6
commit 85a502774c

View File

@ -161,4 +161,20 @@ namespace cruft {
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <typename ValueT> template <typename ValueT>
constexpr auto has_native_v = has_native<ValueT>::value; constexpr auto has_native_v = has_native<ValueT>::value;
///////////////////////////////////////////////////////////////////////////
/// Unconditionally ignore the first argument, and store the second as `type`.
///
/// This aids converting parameter packs types. eg, converting all types
/// to strings by using an expression of the form:
/// `convert_t<ValueT, std::string>...`
template <typename IgnoredT, typename ResultT>
struct convert {
using type = ResultT;
};
template <typename IgnoredT, typename ResultT>
using convert_t = typename convert<IgnoredT, ResultT>::type;
} }