从this代码审查话题起源:的std :: is_constructible没有给出正确的结果
#include <cstddef>
#include <algorithm>
#include <iostream>
#include <type_traits>
#include <utility>
template <typename T>
class aggregate_wrapper : public T {
private:
using base = T;
public:
using aggregate_type = T;
template <typename... Ts>
aggregate_wrapper(Ts&&... xs)
: base{std::forward<Ts>(xs)...} {
// nop
}
};
struct foo_t {
foo_t(int) {}
};
int main() {
std::cout << std::is_constructible<foo_t>::value << std::endl;
std::cout << std::is_constructible<aggregate_wrapper<foo_t>>::value << std::endl;
// aggregate_wrapper<foo_t> v; // won't compile
}
时aggregate_wrapper<foo_t> v;
实际上并不编译怎么可能std::is_constructible<aggregate_wrapper<foo_t>>::value
是真的吗?
也许你在思维上将* constructible *与* default constructible *相混淆?一个'aggregate_wrapper'当然可以被构建,而不是通过'aggregate_wrapper v;'。 –
@ M.M Nope,'is_default_constructible'和'is_constructible '(这意味着'Args ...'是一个空包)是等价的。 –
不知道为什么这是重新打开; dup是直接点。 –