Home » U++ Library support » U++ Core » How to mark std::array<T, N> moveable if only T is moveable
Re: How to mark std::array<T, N> moveable if only T is moveable [message #60707 is a reply to message #60704] |
Fri, 26 July 2024 00:00   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
mirek wrote on Thu, 25 July 2024 04:07
// For instance mark std::array<T, N> moveable if only T is moveable
template <class T, size_t N>
struct NtlMoveableClass<std::array<T, N>>
: std::integral_constant<bool, NtlMoveableClass<T>::value> {};
BTW, easiest and really nice way how to add optional trait:
template <> inline constexpr bool is_moveable<std::string> = true;
(do not want this, but could be useful to know)
Exactly, like it or not, a programmer can mark a class as moveable.
Another not very convincing example.
#include <iostream>
#include <type_traits>
#include <array>
template <class T> struct Moveable {};
template <class T>
inline constexpr bool is_moveable_v = std::is_trivially_copyable<T>::value ||
std::is_base_of<Moveable<T>, T>::value;
class C: public Moveable<C>{
C(const C& c){}
C(C&& c){}
};
// uncomment to communicate the moveability of array<T,n> to the compiler
//template <class T, int n>
//inline constexpr bool is_moveable_v<std::array<T,n>> = is_moveable_v<T>;
int main()
{
std::cout<<is_moveable_v<std::array<C,5>><<std::endl;
}
|
|
|
 |
|
How to mark std::array<T, N> moveable if only T is moveable
By: busiek on Tue, 02 July 2024 17:54
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: Lance on Wed, 03 July 2024 03:39
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Thu, 18 July 2024 08:41
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: busiek on Tue, 23 July 2024 18:25
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Thu, 25 July 2024 02:27
|
 |
 |
Re: How to mark std::array<T, N> moveable if only T is moveable
By: Lance on Thu, 25 July 2024 03:16
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Thu, 25 July 2024 09:19
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Thu, 25 July 2024 09:32
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Thu, 25 July 2024 10:07
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: Lance on Fri, 26 July 2024 00:00
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: busiek on Thu, 25 July 2024 17:32
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Mon, 29 July 2024 08:47
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Fri, 23 August 2024 08:54
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Thu, 18 July 2024 08:44
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: busiek on Thu, 18 July 2024 19:39
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Fri, 19 July 2024 13:11
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: Lance on Fri, 19 July 2024 13:52
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: Lance on Fri, 19 July 2024 14:02
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: Didier on Fri, 19 July 2024 19:10
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: mirek on Mon, 22 July 2024 11:10
|
 |
|
Re: How to mark std::array<T, N> moveable if only T is moveable
By: Lance on Tue, 23 July 2024 01:07
|
Goto Forum:
Current Time: Thu Aug 07 22:05:46 CEST 2025
Total time taken to generate the page: 0.07849 seconds
|