问题:是否有可能通过将其参数传递给内部constexpr函数(可能带有某种"完美转发")来评估函数内部的常量表达式?例:
constexpr size_t foo(char const* string_literal) {
return /*some valid recursive black magic*/;
}
void bar(char const* string_literal) {
// works fine
constexpr auto a = foo("Definitely string literal.");
// compile error: "string_literal" is not a constant expression
constexpr auto b = foo(string_literal);
}
template<typename T>
void baz(T&& string_literal) {
// doesn't compile as well with the same error
constexpr auto b = foo(std::forward<T>(string_literal));
}
int main() {
// gonna do this, wont compile due to errors mentioned above
bar("Definitely …Run Code Online (Sandbox Code Playgroud) 有没有办法创建基类(如boost :: noncopyable)并从中继承,如果它不是由用户(开发人员)制作的,它将禁止编译器为派生类生成默认构造函数?
例:
class SuperDad {
XXX:
SuperDad(); // = delete?
};
class Child : YYY SuperDad {
public:
Child(int a) {...}
};
Run Code Online (Sandbox Code Playgroud)
结果:
int main () {
Child a; // compile error
Child b[7]; // compile error
Child c(13); // OK
}
Run Code Online (Sandbox Code Playgroud)