【发布时间】:2020-01-13 03:15:08
【问题描述】:
指定初始化程序 (C++20) 应该如何与 CTAD 一起使用?
此代码在 gcc9.2 中运行良好,但在 clang8 中失败
template <typename int_t=int, typename float_t=float>
struct my_pair {
int_t first;
float_t second;
};
template<typename ... ts>
my_pair(ts...) -> my_pair<ts...>;
int main() {
my_pair x{.first = 20, .second = 20.f};
static_assert( std::is_same_v<decltype(x.first), int> );
static_assert( std::is_same_v<decltype(x.second), float> );
}
这应该是有效的吗?
【问题讨论】:
-
我在这里链接了一个非常连接的question,因为答案可能对双方都很有趣
标签: c++ c++20 class-template designated-initializer template-argument-deduction