從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是直接點。 –