Array template

I have a big question unresolved.

I have a type called bool_l4v with his own method(functions,operator overloaded...), and I have declared an array using array template like this...

1
2
template<const std::size_t NS>
using B4Term_t = std::array<bool_l4v,NS>;


after this I want to do operation with the array...I dont know if I could do this..

1
2
3
4
5
template<const std::size_t NE,const std::size_t NS>
struct Cube {
	B4Term_t<NE>	cube_in;//this is std::array<bool_l4v,NS>;
	
	constexpr inline bool operator==(const Cube & otro) const { return   (cube_in==otro.cube_in);}


the array is made with bool_l4v which has the operator == overloaded, but the comparing an array I'am comparing more than one value...I dont know if the template array can use the operator == of bool_l4v as many times as NS for itself...

any help??thanks!!

Learn to use references. Look at the std::array class: http://en.cppreference.com/w/cpp/container/array
You can see that it has operator== defined.

Read description of operator==: http://en.cppreference.com/w/cpp/container/array/operator_cmp
Checks if the contents of lhs and rhs are equal, that is, whether each element in lhs compares equal with the element in rhs at the same position.

To check what do you need to ensure that it will work:
T must meet the requirements of EqualityComparable in order to use overloads (1-2).

Read description of EqualityComparable: http://en.cppreference.com/w/cpp/concept/EqualityComparable
To satisfy this requirement, types that do not have built-in comparison operators have to provide a user-defined operator==.



As your bool_l4v overloads operator==, it should be fine.
Last edited on
thank you!!!, I though that It had already a operator == but I was not sure...
Topic archived. No new replies allowed.