【发布时间】:2021-07-08 14:19:36
【问题描述】:
template <typename T>
struct Corresponding;
template <>
struct Corresponding<int> {
using CorrespondingT = boost::multiprecison::cpp_int;
};
template <typename T> using GetCorresponding = typename Corresponding<T>::CorrespondingT;
这可以用作
static_assert(std::is_same_v<GetCorresponding<int>, boost::multiprecision::cpp_int>); // true
其中Corresponding<T> 是包含别名的结构,对应类型为T,在编译时解析。
另一个例子是std::remove_ptr_t<T*>,它对应于T
我可以在 Haskell 中做类似的事情吗,例如
iAmAnInteger :: getCorresponding Int -- Integer
?
我不熟悉 Haskell 在编译时类型方面的能力,但这可能吗?
【问题讨论】:
标签: c++ haskell template-specialization compile-time static-typing