Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
Lance is currently offline  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;
}


 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon14.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Copy the content of a SortedVectorMap
Next Topic: SMTP not working
Goto Forum:
  


Current Time: Thu Aug 07 22:05:46 CEST 2025

Total time taken to generate the page: 0.07849 seconds