Sprout/sprout/string/npos.hpp

132 lines
4.7 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2015-01-10 10:13:57 +00:00
Copyright (c) 2011-2015 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
2012-10-08 14:49:05 +00:00
#ifndef SPROUT_STRING_NPOS_HPP
#define SPROUT_STRING_NPOS_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/is_uint.hpp>
#include <sprout/type_traits/enabler_if.hpp>
2012-10-08 14:49:05 +00:00
namespace sprout {
//
// npos_t
2012-10-08 14:49:05 +00:00
// npos
//
struct npos_t {
2013-02-19 17:23:20 +00:00
public:
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
struct get
: public sprout::integral_constant<UIntType, UIntType(-1)>
2013-02-19 17:23:20 +00:00
{};
public:
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
SPROUT_CONSTEXPR operator UIntType() const {
return UIntType(-1);
}
};
2012-10-08 14:49:05 +00:00
namespace {
2013-02-19 17:23:20 +00:00
SPROUT_STATIC_CONSTEXPR sprout::npos_t npos = {};
2012-10-08 14:49:05 +00:00
} // anonymous-namespace
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator==(UIntType const& lhs, sprout::npos_t rhs) {
return lhs == UIntType(rhs);
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator==(sprout::npos_t lhs, UIntType const& rhs) {
return rhs == lhs;
}
inline SPROUT_CONSTEXPR bool
2013-07-22 13:00:09 +00:00
operator==(sprout::npos_t, sprout::npos_t) {
return true;
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator!=(UIntType const& lhs, sprout::npos_t rhs) {
return !(lhs == rhs);
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::npos_t lhs, UIntType const& rhs) {
return !(lhs == rhs);
}
inline SPROUT_CONSTEXPR bool
operator!=(sprout::npos_t lhs, sprout::npos_t rhs) {
return !(lhs == rhs);
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator<(UIntType const& lhs, sprout::npos_t rhs) {
return lhs < UIntType(rhs);
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator<(sprout::npos_t lhs, UIntType const& rhs) {
return rhs == lhs;
}
inline SPROUT_CONSTEXPR bool
2013-07-22 13:00:09 +00:00
operator<(sprout::npos_t, sprout::npos_t) {
return false;
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator>(UIntType const& lhs, sprout::npos_t rhs) {
return rhs < lhs;
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator>(sprout::npos_t lhs, UIntType const& rhs) {
return rhs < lhs;
}
inline SPROUT_CONSTEXPR bool
operator>(sprout::npos_t lhs, sprout::npos_t rhs) {
return rhs < lhs;
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator<=(UIntType const& lhs, sprout::npos_t rhs) {
return !(rhs < lhs);
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::npos_t lhs, UIntType const& rhs) {
return !(rhs < lhs);
}
inline SPROUT_CONSTEXPR bool
operator<=(sprout::npos_t lhs, sprout::npos_t rhs) {
return !(rhs < lhs);
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator>=(UIntType const& lhs, sprout::npos_t rhs) {
return !(lhs < rhs);
}
template<typename UIntType, typename sprout::enabler_if<sprout::is_uint<UIntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::npos_t lhs, UIntType const& rhs) {
return !(lhs < rhs);
}
inline SPROUT_CONSTEXPR bool
operator>=(sprout::npos_t lhs, sprout::npos_t rhs) {
return !(lhs < rhs);
}
2012-10-08 14:49:05 +00:00
} // namespace sprout
#endif // #ifndef SPROUT_STRING_NPOS_HPP