#include <iostream>

using namespace std;

template<int N>
struct int_
{
    static const int value = N;
    typedef int_<N> type;
    typedef int value_type;

    typedef int_<N + 1> next;
    typedef int_<N - 1> prior;
    operator int() const
    {
        return N;
    }
};


int main()
{
    cout << typeid(int_<6>::type).name() << endl;
    cout << typeid(int_<6>::value_type).name() << endl;
    cout << int_<6>::value << endl;
    cout << int_<6>() << endl;
    cout << int_<6>::next::value << endl;
    cout << int_<6>::prior::value << endl;

    cout << typeid(int_<false>::type).name() << endl;
    cout << int_<false>::value << endl;
    cout << int_<false>::next::value << endl;
    cout << int_<false>::prior::value << endl;
    cout << typeid(int_<true>::type).name() << endl;
    cout << int_<true>::value << endl;
    cout << int_<true>::next::value << endl;
    cout << int_<true>::prior::value << endl;

    return 0;
}

结果:

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐