源自于 这个 CodeReview 主题:
#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>
不能编译时,为什么std::is_constructible<aggregate_wrapper<foo_t>>::value
会为真?
aggregate_wrapper<foo_t>
肯定可以被构造,只是不能通过aggregate_wrapper<foo_t> v;
这种方式。 - M.Mis_default_constructible<T>
和is_constructible<T>
(这意味着Args...
是一个空包)是等价的。 - T.C.