Inlined free functions for ODR

This commit is contained in:
Krystian Stasiowski
2019-10-27 21:01:44 -04:00
parent fca9d8e01f
commit 5c81f47f7f
4 changed files with 74 additions and 11 deletions

View File

@ -11,7 +11,7 @@
#define BOOST_FIXED_STRING_CONFIG_HPP #define BOOST_FIXED_STRING_CONFIG_HPP
// Are we dependent on Boost? // Are we dependent on Boost?
//#define BOOST_FIXED_STRING_USE_BOOST #define BOOST_FIXED_STRING_USE_BOOST
// C++ version // C++ version
#if __cplusplus >= 201703L #if __cplusplus >= 201703L

View File

@ -19,6 +19,9 @@ namespace boost {
namespace fixed_string { namespace fixed_string {
namespace detail { namespace detail {
template<std::size_t, typename, typename>
class fixed_string;
// Because k-ballo said so // Because k-ballo said so
template<class T> template<class T>
using is_input_iterator = using is_input_iterator =
@ -26,6 +29,7 @@ using is_input_iterator =
! std::is_integral<T>::value>; ! std::is_integral<T>::value>;
template<typename CharT, typename Traits> template<typename CharT, typename Traits>
inline
int int
lexicographical_compare( lexicographical_compare(
CharT const* s1, std::size_t n1, CharT const* s1, std::size_t n1,
@ -43,6 +47,7 @@ lexicographical_compare(
#ifdef BOOST_FIXED_STRING_STRING_VIEW #ifdef BOOST_FIXED_STRING_STRING_VIEW
template<typename CharT, typename Traits> template<typename CharT, typename Traits>
inline
int int
lexicographical_compare( lexicographical_compare(
basic_string_view<CharT, Traits> s1, basic_string_view<CharT, Traits> s1,
@ -53,8 +58,20 @@ lexicographical_compare(
} }
#endif #endif
template<std::size_t N, typename CharT, typename Traits >
inline
int
lexicographical_compare(
const fixed_string<N, CharT, Traits>& s1,
CharT const* s2, std::size_t n2)
{
return detail::lexicographical_compare<
CharT, Traits>(s1.data(), s1.size(), s2, n2);
}
#ifdef BOOST_FIXED_STRING_STRING_VIEW #ifdef BOOST_FIXED_STRING_STRING_VIEW
template<typename CharT, typename Traits> template<typename CharT, typename Traits>
inline
int int
lexicographical_compare( lexicographical_compare(
basic_string_view<CharT, Traits> s1, basic_string_view<CharT, Traits> s1,
@ -65,6 +82,17 @@ lexicographical_compare(
} }
#endif #endif
template<std::size_t N, std::size_t M, typename CharT, typename Traits>
inline
int
lexicographical_compare(
const fixed_string<N, CharT, Traits>& s1,
const fixed_string<M, CharT, Traits>& s2)
{
return detail::lexicographical_compare<CharT, Traits>(
s1.data(), s1.size(), s2.data(), s2.size());
}
// Maximum number of characters in the decimal // Maximum number of characters in the decimal
// representation of a binary number. This includes // representation of a binary number. This includes
// the potential minus sign. // the potential minus sign.
@ -78,6 +106,7 @@ max_digits(std::size_t bytes)
} }
template<typename CharT, class Integer, typename Traits> template<typename CharT, class Integer, typename Traits>
inline
CharT* CharT*
raw_to_string( raw_to_string(
CharT* buf, Integer x, std::true_type) CharT* buf, Integer x, std::true_type)
@ -103,6 +132,7 @@ raw_to_string(
} }
template<typename CharT, class Integer, typename Traits> template<typename CharT, class Integer, typename Traits>
inline
CharT* CharT*
raw_to_string( raw_to_string(
CharT* buf, Integer x, std::false_type) CharT* buf, Integer x, std::false_type)
@ -122,6 +152,7 @@ template<
typename CharT, typename CharT,
class Integer, class Integer,
typename Traits = std::char_traits<CharT>> typename Traits = std::char_traits<CharT>>
inline
CharT* CharT*
raw_to_string(CharT* last, std::size_t size, Integer i) raw_to_string(CharT* last, std::size_t size, Integer i)
{ {
@ -135,7 +166,8 @@ template<
typename Traits, typename Traits,
typename CharT, typename CharT,
typename ForwardIt> typename ForwardIt>
ForwardIt inline
ForwardIt
find_not_of( find_not_of(
ForwardIt first, ForwardIt last, const CharT* str, std::size_t n) noexcept ForwardIt first, ForwardIt last, const CharT* str, std::size_t n) noexcept
{ {

View File

@ -1954,30 +1954,35 @@ private:
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
void void
operator+( operator+(
fixed_string<N, CharT, Traits>const& lhs, fixed_string<N, CharT, Traits>const& lhs,
fixed_string<M, CharT, Traits>const& rhs) = delete; fixed_string<M, CharT, Traits>const& rhs) = delete;
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
void void
operator+( operator+(
CharT const* lhs, CharT const* lhs,
fixed_string<N, CharT, Traits>const& rhs) = delete; fixed_string<N, CharT, Traits>const& rhs) = delete;
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
void void
operator+( operator+(
CharT lhs, CharT lhs,
fixed_string<N, CharT, Traits> const& rhs) = delete; fixed_string<N, CharT, Traits> const& rhs) = delete;
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
void void
operator+( operator+(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
CharT const* rhs) = delete; CharT const* rhs) = delete;
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
void void
operator+( operator+(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -1992,6 +1997,7 @@ operator+(
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
bool bool
operator==( operator==(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2003,6 +2009,7 @@ operator==(
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
bool bool
operator!=( operator!=(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2014,6 +2021,7 @@ operator!=(
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
bool bool
operator<( operator<(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2025,6 +2033,7 @@ operator<(
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
bool bool
operator<=( operator<=(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2036,6 +2045,7 @@ operator<=(
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
bool bool
operator>( operator>(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2047,6 +2057,7 @@ operator>(
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
bool bool
operator>=( operator>=(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2056,6 +2067,7 @@ operator>=(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator==( operator==(
CharT const* lhs, CharT const* lhs,
@ -2067,6 +2079,7 @@ operator==(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator==( operator==(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2078,6 +2091,7 @@ operator==(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator!=( operator!=(
CharT const* lhs, CharT const* lhs,
@ -2089,6 +2103,7 @@ operator!=(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator!=( operator!=(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2100,6 +2115,7 @@ operator!=(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator<( operator<(
CharT const* lhs, CharT const* lhs,
@ -2111,6 +2127,7 @@ operator<(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator<( operator<(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2122,6 +2139,7 @@ operator<(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator<=( operator<=(
CharT const* lhs, CharT const* lhs,
@ -2133,6 +2151,7 @@ operator<=(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator<=( operator<=(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2144,6 +2163,7 @@ operator<=(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator>( operator>(
CharT const* lhs, CharT const* lhs,
@ -2155,6 +2175,7 @@ operator>(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator>( operator>(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2166,6 +2187,7 @@ operator>(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator>=( operator>=(
CharT const* lhs, CharT const* lhs,
@ -2177,6 +2199,7 @@ operator>=(
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
bool bool
operator>=( operator>=(
fixed_string<N, CharT, Traits> const& lhs, fixed_string<N, CharT, Traits> const& lhs,
@ -2193,7 +2216,11 @@ operator>=(
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
template<std::size_t N, typename CharT, typename Traits> template<
std::size_t N,
typename CharT,
typename Traits>
inline
void void
swap( swap(
fixed_string<N, CharT, Traits>& lhs, fixed_string<N, CharT, Traits>& lhs,
@ -2205,6 +2232,7 @@ swap(
template< template<
std::size_t N, std::size_t M, std::size_t N, std::size_t M,
typename CharT, typename Traits> typename CharT, typename Traits>
inline
void void
swap( swap(
fixed_string<N, CharT, Traits>& lhs, fixed_string<N, CharT, Traits>& lhs,
@ -2219,16 +2247,17 @@ swap(
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifdef BOOST_FIXED_STRING_STRING_VIEW
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
inline
std::basic_ostream<CharT, Traits>& std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, operator<<(std::basic_ostream<CharT, Traits>& os,
fixed_string<N, CharT, Traits> const& s) fixed_string<N, CharT, Traits> const& s)
{ {
return os << static_cast< // for the non-trivial CharT
string_view>(s); for (const CharT& c : s)
os << c;
return os;
} }
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
@ -2252,6 +2281,7 @@ template<
std::is_integral<Integer>::value>::type std::is_integral<Integer>::value>::type
#endif #endif
> >
inline
fixed_string<detail::max_digits(sizeof(Integer))> fixed_string<detail::max_digits(sizeof(Integer))>
to_fixed_string(Integer x); to_fixed_string(Integer x);

View File

@ -787,6 +787,7 @@ assign_char(CharT, std::false_type) ->
} }
template<class Integer, class> template<class Integer, class>
inline
fixed_string<detail::max_digits(sizeof(Integer))> fixed_string<detail::max_digits(sizeof(Integer))>
to_fixed_string(Integer x) to_fixed_string(Integer x)
{ {