template<typename T,typename U>
concept bool forwardable = requires(U u)
{
{T(u)};
};
class name
{
std::string str;
public:
template<forwardable<std::string> T>
name(T &&_s):str(std::forward<T>(_s)){}
const std::string& string() const
{
return str;
}
};
template<forwardable<std::string> T>
name(T &&_s):str(std::forward<T>(_s)){}
template<typename T,typename U>
concept bool forwardable = requires(T&& t)
{
U(static_cast<T&&>(t));
};
class f
{
std::string __name;
public:
f(const std::string& _name):__name(_name){}
f(std::string&& _name):__name(std::move(_name)){}
const std::string& name() const
{
return __name;
}
};However, it just chaotic when parameter numbers are more than 1. The function will be written for 2^n times to handle both const T& or T&& problem.
Is this better by passing T directly? I think this method is satisfied basic exception safe.class f
{
std::string __name;
public:
f(std::string _name):__name(std::move(_name)){}
const std::string& name() const
{
return __name;
}
};
template<typename T,typename U>
concept bool forwardable = requires(T&& t)
{
U(static_cast<T&&>(t));
};
template<typename T, typename U>
concept bool forwardable = requires (T&& t) {
template<typename T,typename ...Args>
concept bool forwardable = requires(Args&&... args)
{
{T(std::forward<Args>(args)...)}
};
I have a better version.
template<typename T,typename ...Args>
concept bool forwardable = requires(Args&&... args)
{
{T(std::forward<Args>(args)...)}
};
prog.cc:8:47: internal compiler error: Segmentation fault concept bool forwardable = requires(Ts &&... ts)