filter - TumpCpp リファレンス
namespace tump {
namespace fn {
// 大元のメタ関数定義
template <InvocableArgN<1> Pred, TypeList List>
using filter = ...;
}
// 第一級関数化
using filter = cbk<fn::filter, 2>;
// メンバ型 type 呼び出し省略のエイリアステンプレート
template <InvocableArgN<1> Pred, TypeList List>
using filter_t = typename fn::filter<Pred, List>::type;
}
パラメータ
- Pred -
tump::InvocableArgN<1>で真と判定されるメタ関数 - List -
tump::TypeListで真と判定される型のリスト
概要
tump::filterは、テンプレートパラメータListが保持するパラメータパックのうち、テンプレートパラメータPredのメタ関数を適用した結果、真と判定されるような型を抽出するメタ関数です。
例
#include <tuple>
#include <vector>
#include <tump.hpp>
class A {};
using list1 = tump::list<int, float, void, std::vector<int>, char>;
using list2 = std::tuple<int, float, A, std::vector<int>, double>;
static_assert(std::is_same_v<
tump::filter_t<tump::is_integral, list1>,
tump::list<int, char>
> == true);
static_assert(std::is_same_v<
tump::filter_t<tump::is_floating_point, list2>,
std::tuple<float, double>
> == true);
static_assert(tump::eval<
tump::filter, tump::is_void, list1,
tump::_eq,
tump::list<void>
>::value == true);
static_assert(tump::eval<
tump::filter, tump::is_arithmetic, list2,
tump::_eq,
std::tuple<int, float, double>
>::value == true);
int main() {}