C++ 正在与Boost.Mp11抗争:“您必须遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他有关法律法规。”;需要一个类模板,得到';T'&引用;

C++ 正在与Boost.Mp11抗争:“您必须遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他有关法律法规。”;需要一个类模板,得到';T'&引用;,c++,boost,boost-mp11,C++,Boost,Boost Mp11,我试图使用Boost.Mp11检查特殊类型元组的非特殊唯一性: #include <iostream> #include <vector> #include <deque> #include <tuple> #include <boost/mp11/algorithm.hpp> namespace { template <typename T, template <typename...> typename U&g

我试图使用Boost.Mp11检查特殊类型元组的非特殊唯一性:

#include <iostream>
#include <vector>
#include <deque>
#include <tuple>

#include <boost/mp11/algorithm.hpp>

namespace
{
template <typename T, template <typename...> typename U>
struct is_specialisation : std::false_type {};

template <template <typename...> typename U, typename... Args>
struct is_specialisation<U<Args...>, U> : std::true_type {};

template <template <typename...> typename U>
struct is_specialisation_meta
{
    template <typename T>
    using type = is_specialisation<T, U>;
};

template <typename TypeList>
struct unique_specialisation
{
    template <typename T>
    using type = std::is_same<
        boost::mp11::mp_count_if<
            TypeList,
            is_specialisation_meta<T>::template type // Error!
        >,
        boost::mp11::mp_size_t<1>
    >;
};
}

int main()
{
    using types = std::tuple<
        std::vector<int>,
        std::deque<int>,
        std::tuple<int>
    >;

    using all_unique_specialisations = boost::mp11::mp_all_of<
        types,
        unique_specialisation<types>::template type
    >;

    std::cout << std::boolalpha << all_unique_specialisations::value << std::endl;

    return EXIT_SUCCESS;
}
#包括
#包括
#包括
#包括
#包括
名称空间
{
模板
结构是_专门化:std::false _type{};
模板

结构是专业化的直接错误是

template <typename T>
using type = std::is_same<
    boost::mp11::mp_count_if<
        TypeList,
        is_specialisation_meta<T>::template type // Error!
    >,
    boost::mp11::mp_size_t<1>
>;
模板
使用type=std::是否相同<
boost::mp11::mp\u计数\u如果<
类型列表,
is_Specialization_meta::模板类型//错误!
>,
boost::mp11::mp\u大小\u t
>;
如果我们把它和

template <template <typename...> typename U>
struct is_specialisation_meta
模板
结构是专业化的
…我们看到代码传递了一个typename
T
,其中需要一个模板
U
。但是修改它只会将错误转移到其他地方,因为现在
boost.mp
无法获得它所需的谓词类型。恐怕我对库不太熟悉,无法告诉您如何获得超出此范围的工作版本。

#包括
#包括
#包括
#包括
#包括
名称空间
{
模板
结构是_专门化:std::false _type{};
模板
结构是_专门化:std::true_类型{};
模板结构是_specialization _meta;//已添加
模板//已更改
结构是专业化的
{
模板
使用类型=is_专业化;
};
模板
结构独特专业化
{
模板
使用type=std::是否相同<
boost::mp11::mp\u计数\u如果<
类型列表,
is_Specialization_meta::模板类型//错误!
>,
boost::mp11::mp\u大小\u t
>;
};
}
int main()
{
使用types=std::tuple<
向量,
德克,
std::tuple
>;
使用types2=std::tuple<
向量,
向量,
std::tuple
>;
使用所有独特的专业化=boost::mp11::mp\u所有<
类型,
独特的专业化::模板类型
>;
使用所有独特的专业2=boost::mp11::mp\u所有<
类型2,
独特的专业化::模板类型
>;

std::cout什么是“非特殊等价物”?我不理解你的例子
{std::vector,std::deque,std::tuple}
vs
{std::vector,std::vector,std::tuple}
@m.s.
std::vector
std::vector
上的
int
的专业化,因此
std::vector
是非专业化类型。该算法尝试查找非专业化类型的倍数(即检查非专业化唯一性)。第一个示例通过是因为每个非专业化类型都不同,而第二个失败是因为有两个
std::vector
s。很好,谢谢!你能解释一下为什么我的方法不起作用吗?StoryTeller的回答解释了这一点,你可能应该接受它。你传递的是一个类型(
std::vector
),其中“类模板”是预期的(
std::vector
)。我已将
is\u specialization\u meta
更改为接受类型,并从中推断出相应的“非专业类模板”“。如果您传递的类型不是专门化类型,则会出现另一个错误,您需要更改主模板的行为。@llonesmiz请接受StoryTeller的建议作为实际答案。”
template <template <typename...> typename U>
struct is_specialisation_meta
#include <iostream>
#include <vector>
#include <deque>
#include <tuple>

#include <boost/mp11/algorithm.hpp>

namespace
{
template <typename T, template <typename...> typename U>
struct is_specialisation : std::false_type {};

template <template <typename...> typename U, typename... Args>
struct is_specialisation<U<Args...>, U> : std::true_type {};

template <typename T> struct is_specialisation_meta;//ADDED

template <template <typename... > typename U, typename... Args>//CHANGED
struct is_specialisation_meta<U<Args...>>
{
    template <typename T>
    using type = is_specialisation<T, U>;
};

template <typename TypeList>
struct unique_specialisation
{
    template <typename T>
    using type = std::is_same<
        boost::mp11::mp_count_if<
            TypeList,
            is_specialisation_meta<T>::template type // Error!
        >,
        boost::mp11::mp_size_t<1>
    >;
};
}

int main()
{
    using types = std::tuple<
        std::vector<int>,
        std::deque<int>,
        std::tuple<int>
    >;

    using types2 = std::tuple<
        std::vector<int>,
        std::vector<float>,
        std::tuple<int>
    >;

    using all_unique_specialisations = boost::mp11::mp_all_of<
        types,
        unique_specialisation<types>::template type
    >;

    using all_unique_specialisations2 = boost::mp11::mp_all_of<
        types2,
        unique_specialisation<types2>::template type
    >;

    std::cout << std::boolalpha << all_unique_specialisations::value << std::endl;
    std::cout << std::boolalpha << all_unique_specialisations2::value << std::endl;

    return EXIT_SUCCESS;
}