Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板专门化问题_C++_Visual Studio 2008_Templates_Metaprogramming_Specialization - Fatal编程技术网

C++ 模板专门化问题

C++ 模板专门化问题,c++,visual-studio-2008,templates,metaprogramming,specialization,C++,Visual Studio 2008,Templates,Metaprogramming,Specialization,我真的很努力让这项工作成功,但我没有运气。我肯定有工作要做,但我还没有遇到过。好的,让我们看看我能否简单地描述问题和需求: 我有一个RGB模板类,它可以将TypeName作为模板参数之一。它接受typename并将其发送到另一个模板中,该模板创建其基本类型的分类。例如: struct float_type {}; struct bit_type {}; struct fixed_pt_type {}; template <typename T> struct type_specif

我真的很努力让这项工作成功,但我没有运气。我肯定有工作要做,但我还没有遇到过。好的,让我们看看我能否简单地描述问题和需求:

我有一个RGB模板类,它可以将TypeName作为模板参数之一。它接受typename并将其发送到另一个模板中,该模板创建其基本类型的分类。例如:

struct float_type {};
struct bit_type {};
struct fixed_pt_type {};

template <typename T> struct type_specification { typedef float_type type; };

template <> struct type_specification<char>      { typedef bit_type type; };
template <> struct type_specification<short>     { typedef bit_type type; };
template <> struct type_specification<int>       { typedef bit_type type; };
template <> struct type_specification<long>      { typedef bit_type type; };
template <> struct type_specification<long long> { typedef bit_type type; };
struct float_type{};
结构位_类型{};
结构固定型{};
模板结构类型_规范{typedef float_type;};
模板结构类型_规范{typedef bit_type;};
模板结构类型_规范{typedef bit_type;};
模板结构类型_规范{typedef bit_type;};
模板结构类型_规范{typedef bit_type;};
模板结构类型_规范{typedef bit_type;};
然后,我有了一个模板,可以根据每个RGB值的位计数计算其最大值:

template <int Bits, typename T> struct Max_Values { enum { MaxValue = (1 << Bits) - 1; }; };
template <int Bits> struct MaxValues<float_type>  { enum { MaxValue = 1.0; }; };

template struct Max_Values{enum{MaxValue=(1也许我遗漏了一些更复杂的问题,但是有什么原因不能部分地专门化
type_规范
模板吗

大概是这样的:

template <int N, typename T, template <class> class Policy>
struct type_specification< fixed_pt_t<N, T, Policy> >
{
    typedef fixed_pt_type type;
};
模板
结构类型规范
{
typedef固定式_pt_类型;
};

也许我遗漏了一些更复杂的问题,但是有什么理由不能部分地专门化
type\u规范
模板吗

大概是这样的:

template <int N, typename T, template <class> class Policy>
struct type_specification< fixed_pt_t<N, T, Policy> >
{
    typedef fixed_pt_type type;
};
模板
结构类型规范
{
typedef固定式_pt_类型;
};

你知道,我确实试过了,但它从来没有运行过代码。我认为这是因为max values::value是用一个类型名T运行的(在本例中是fixed-pt-T)它使用了简单的专门化。哦,糟糕。你知道吗。它确实起作用了。我只是没有正确设置最大值的方程,所以我认为它没有运行代码。我已经在墙上撞了几天了!谢谢,你的解决方案很好!好吧,那没关系,我只是在为ch开发一个快速测试应用程序请检查我的理智。我只想指出,你的问题中有很多地方缺少关键字
struct
。也许你想编辑使其更易于编译。是的,我在那里添加了所有的struct关键字,使其更易于编译。我等不及了,直到模板元编程更易于调试!你知道,我实际上是这样做的我试过了,但它从未运行过代码。我认为这是因为max-values::value是用一个类型名T运行的(在本例中是fixed-pt-T)它使用了简单的专门化。哦,糟糕。你知道吗。它确实起作用了。我只是没有正确设置最大值的方程,所以我认为它没有运行代码。我已经在墙上撞了几天了!谢谢,你的解决方案很好!好吧,那没关系,我只是在为ch开发一个快速测试应用程序检查我的理智。我只想指出,你的问题中有很多地方缺少关键字
struct
。也许你想编辑使其更易于编译。是的,我在那里添加了所有的struct关键字,使其更易于编译。我等不及模板元编程更易于调试了!
template <int N, typename T, template <class> class Policy> struct fixed_pt_t
template <int N, typename T, template <class> class Policy>
struct type_specification< fixed_pt_t<N, T, Policy> >
{
    typedef fixed_pt_type type;
};