Talk:cpp/concepts/semiregular
From cppreference.com
Hi Everyone
Does below code will be an example for semiregular?? Inplace of typename i just want to use semiregular to my T??
Is this how i need to use semiregular concepts constraint on my T?
If not can anyone suggest on how to use it?
template <typename T>
requries semiregular<T>
OR
template <semiregular T> struct Single { typedef T value_type; T value; explicit Single(const T& x) : value(x) {} Single(const Single& x) : value(x.value) {} Single() {} ~Single() {} Single& operator=(const Single& x, const Single& y){ value = x.value; return *this; } };
--Dotyes (talk) 02:32, 19 September 2019 (PDT)Mohan
- Both forms are OK. And it's better to leave all special member functions implicitly defined than manually define them. --Fruderica (talk) 04:18, 19 September 2019 (PDT)
And it's better to leave all special member functions implicitly defined than manually define them means I should'nt define special member function like default constructor, copy constructor, destructor and assignment for my user defined class??
template<semiregular T> struct Single { T value; }; #include <concepts> int main(){ Single<int> myInt(4); std::cout << myInt.value; return 0; }
Will this code works?? I'm correct in understanding your answer?? --Dotyes (talk) 04:24, 22 September 2019 (PDT)Mohan
- You should write std::cout << myInt.value instead of std::cout << myInt, and write #include <concepts> at first. Whether leave special member functions implicitly defined is better depends on the behavior of your class. --Fruderica (talk) 07:35, 22 September 2019 (PDT)
Thank you so much @Fruderica.