NM
Size: a a a
NM
Д
pair p{1, Type<int>}->
p.second()::type
Д
АК
pair p{1, Type<int>}->
p.second()::type
template <class T>
struct Type {};
std::pair<int, Type<int>>{ 1, {} }
, но тип каждой пары будет разным в зависимости от Type<T>
АК
АК
pair p{1, Type<int>}->
p.second()::type
Type
реализуется через засовывание в std::function<void()>
логики, которую необходимо сделать с конкретным типом позднее (type erasure)AS
pair p{1, Type<int>}->
p.second()::type
#include <any>
#include <iostream>
#include <map>
#include <string>
int main() {
std::map<int, std::any> m;
m[1] = std::string("hello");
m[2] = 10.0;
m[3] = 20;
std::cout << std::any_cast<std::string>(m[1]);
std::cout << std::any_cast<double>(m[2]);
std::cout << std::any_cast<int>(m[3]);
}
AS
AS
Д
Д
AS
ip
ip
template <Scale To, Scale From>
struct ConversionTraits {
static temperature_t convert(const temperature_t value) = delete;
};
template <>
struct ConversionTraits<Scale::kCelsius, Scale::kFahrenheit> {
static temperature_t convert(const temperature_t value) {
return value * 9 / 5 + 32;
}
};
template <>
struct ConversionTraits<Scale::kFahrenheit, Scale::kCelsius> {
static temperature_t convert(const temperature_t value) {
return (value - 32) * 5 / 9;
}
};
template <Scale To, Scale From>
constexpr Quantity<To> temperature_cast(const Quantity<From>& t) {
return Quantity<To>(ConversionTraits<From, To>::convert(static_cast<temperature_t>(t)));
}
Д
Д
Д
AS
AS
cast<INT>(storage)и другое дело void func(int type) {..,..}