IMO "-" " -" . , "-", , . , , ( " ": ) ( " ": ).
, , .. S
. S
. , , , , . mapping
. , , .. mapping
. map
.
:
template<typename X> struct mapping {
using type = int;
};
template<> struct mapping<bool> {
using type = double;
};
map
, , - mapping
:
template<template<typename...> class List,
template<typename> class Mapping>
struct map {
template<typename... Elements>
using type = List<typename Mapping<Elements>::type...>;
};
, Example
( , "" ) mapping
:
template<typename... S>
using MappedExample = map<Example, mapping>::type<S...>;
, -:
template<typename... S>
MappedExample<S...> f() {
return MappedExample<S...>{};
}
:
int main() {
std::cout
<< typeid(Example<bool,int,char,double>).name()
<< std::endl
<< typeid(decltype(f<bool, int, char, double>())).name()
<< std::endl;
}
:
7ExampleIJbicdEE
Example
b ool, i nt, c har, d ouble.
7ExampleIJdiiiEE
Example
d ( bool) 3 i nt ( ).