Core/Flags: Move external operators to the global scope

Fixes usage of those operators outside of the Nz namespace, global
scoping is not an issue thanks to the enable_if
This commit is contained in:
Lynix 2017-02-15 07:13:00 +01:00
parent 1a677387d1
commit 7cc11245f9
2 changed files with 62 additions and 63 deletions

View File

@ -54,13 +54,13 @@ namespace Nz
private:
BitField m_value;
};
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs);
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs);
}
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs);
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator|(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator&(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator^(E lhs, E rhs);
#include <Nazara/Core/Flags.inl>
#endif // NAZARA_FLAGS_HPP

View File

@ -209,68 +209,67 @@ namespace Nz
{
return 1U << static_cast<BitField>(enumValue);
}
}
/*!
* \brief Override binary NOT operator on enum to turns into a Flags object.
* \return A Flags object with reversed bits.
*
* \param lhs Enumeration value to reverse.
*
* Returns a Flags object with all state enabled except for the enum one.
*/
template<typename E>
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs)
{
return ~Nz::Flags<E>(lhs);
}
/*!
* \brief Override binary NOT operator on enum to turns into a Flags object.
* \return A Flags object with reversed bits.
*
* \param lhs Enumeration value to reverse.
*
* Returns a Flags object with all state enabled except for the enum one.
*/
template<typename E>
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs)
{
return ~Flags<E>(lhs);
}
/*!
* \brief Override binary OR operator on enum to turns into a Flags object.
* \return A Flags object with combined enum states.
*
* \param lhs First enumeration value to combine.
* \param rhs Second enumeration value to combine.
*
* Returns a Flags object with combined states from the two enumeration values.
*/
template<typename E>
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator|(E lhs, E rhs)
{
return Nz::Flags<E>(lhs) | rhs;
}
/*!
* \brief Override binary OR operator on enum to turns into a Flags object.
* \return A Flags object with combined enum states.
*
* \param lhs First enumeration value to combine.
* \param rhs Second enumeration value to combine.
*
* Returns a Flags object with combined states from the two enumeration values.
*/
template<typename E>
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs)
{
return Flags<E>(lhs) | rhs;
}
/*!
* \brief Override binary AND operator on enum to turns into a Flags object.
* \return A Flags object with compare enum states.
*
* \param lhs First enumeration value to compare.
* \param rhs Second enumeration value to compare.
*
* Returns a Flags object with compared states from the two enumeration values.
* In this case, only one flag will be enabled if both enumeration values are the same.
*/
template<typename E>
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator&(E lhs, E rhs)
{
return Nz::Flags<E>(lhs) & rhs;
}
/*!
* \brief Override binary AND operator on enum to turns into a Flags object.
* \return A Flags object with compare enum states.
*
* \param lhs First enumeration value to compare.
* \param rhs Second enumeration value to compare.
*
* Returns a Flags object with compared states from the two enumeration values.
* In this case, only one flag will be enabled if both enumeration values are the same.
*/
template<typename E>
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs)
{
return Flags<E>(lhs) & rhs;
}
/*!
* \brief Override binary XOR operator on enum to turns into a Flags object.
* \return A Flags object with XORed enum states.
*
* \param lhs First enumeration value to compare.
* \param rhs Second enumeration value to compare.
*
* Returns a Flags object with XORed states from the two enumeration values.
* In this case, two flags will be enabled if both the enumeration values are different.
*/
template<typename E>
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs)
{
return Flags<E>(lhs) ^ rhs;
}
/*!
* \brief Override binary XOR operator on enum to turns into a Flags object.
* \return A Flags object with XORed enum states.
*
* \param lhs First enumeration value to compare.
* \param rhs Second enumeration value to compare.
*
* Returns a Flags object with XORed states from the two enumeration values.
* In this case, two flags will be enabled if both the enumeration values are different.
*/
template<typename E>
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator^(E lhs, E rhs)
{
return Nz::Flags<E>(lhs) ^ rhs;
}
#include <Nazara/Core/DebugOff.hpp>