Dec 2, 2014

[C++14] variable template for fun.

#include <iostream>
using namespace std;


template<typename T>
struct Gen
{
    operator T()
    {
        return T{42};
    }
};


struct FunType
{
    int _val;
    template<template<typename> class Gen>
    FunType(Gen<int> g) : _val{g}
    {}
};


template<typename T, template<typename> class Gen = Gen>
T JustForFun{Gen<int>()};


int main()
{
    cout << JustForFun<FunType>._val << endl;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.