相关疑难解决方法(0)

概念和模板约束之间有什么区别?

我想知道C++完整概念提议和模板约束之间的语义差异(例如,Dlang中出现的约束或C++ 1y的新概念 - 精简提议).

什么是能够比模板约束做的完整概念不能做到的?

c++ d c++11 c++-concepts

95
推荐指数
2
解决办法
2万
查看次数

模板约束C++

在C#中,我们可以定义一个泛型类型,它对可用作泛型参数的类型施加约束.以下示例说明了泛型约束的用法:

interface IFoo
{
}


class Foo<T> where T : IFoo
{
}

class Bar : IFoo
{
}

class Simpson
{
}

class Program
{
    static void Main(string[] args)
    {
        Foo<Bar> a = new Foo<Bar>();
        Foo<Simpson> b = new Foo<Simpson>(); // error CS0309
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法可以在C++中对模板参数施加约束.


C++ 0x本身支持这个,但我说的是当前的标准C++.

c++ templates constraints

62
推荐指数
6
解决办法
4万
查看次数

标签 统计

c++ ×2

c++-concepts ×1

c++11 ×1

constraints ×1

d ×1

templates ×1