#include <type_traits>
template< typename T, T V, typename = void > struct integral_c ;
// a la std::integral_constant http://e...content-available-to-author-only...e.com/w/cpp/types/integral_constant
template< typename T, T V >
struct integral_c< T, V, typename std::enable_if< std::is_integral<T>::value >::type >
{
static constexpr T value = V ;
typedef T value_type ;
typedef integral_c type ;
constexpr operator value_type() const { return value ; }
};
template< int N > struct int_ : integral_c<int,N> {} ;
template< long N > struct long_ : integral_c<long,N> {} ;
template < typename T, typename U > struct plus : integral_c<
typename std::common_type< typename T::value_type, typename U::value_type >::type,
T::value + U::value > {} ;
#include <iostream>
#include <functional>
int main()
{
typedef int_<5> five ;
typedef long_<7> seven ;
typedef plus<five,seven> twelve ;
static_assert( std::is_same< twelve::value_type, long >::value, "error in common_type" ) ;
std::cout << twelve::value << '\n' ; // 12
std::cout << std::minus<long>()( twelve(), five() ) << '\n' // 7
<< twelve() * seven() << '\n' ; // 84
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgoKdGVtcGxhdGU8IHR5cGVuYW1lIFQsIFQgViwgdHlwZW5hbWUgPSB2b2lkID4gc3RydWN0IGludGVncmFsX2MgOwoKLy8gYSBsYSBzdGQ6OmludGVncmFsX2NvbnN0YW50IGh0dHA6Ly9lLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5lLmNvbS93L2NwcC90eXBlcy9pbnRlZ3JhbF9jb25zdGFudAp0ZW1wbGF0ZTwgdHlwZW5hbWUgVCwgVCBWID4Kc3RydWN0IGludGVncmFsX2M8IFQsIFYsIHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPCBzdGQ6OmlzX2ludGVncmFsPFQ+Ojp2YWx1ZSA+Ojp0eXBlID4KewogICAgc3RhdGljIGNvbnN0ZXhwciBUIHZhbHVlID0gViA7CiAgICB0eXBlZGVmIFQgdmFsdWVfdHlwZSA7CiAgICB0eXBlZGVmIGludGVncmFsX2MgdHlwZSA7CiAgICBjb25zdGV4cHIgb3BlcmF0b3IgdmFsdWVf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