add complex tuple and container support

This commit is contained in:
bolero-MURAKAMI 2014-07-10 17:08:33 +09:00
parent f4d715c6db
commit 54920b3389
11 changed files with 357 additions and 100 deletions

View file

@ -14,6 +14,8 @@
#include <sprout/complex/values.hpp>
#include <sprout/complex/transcendentals.hpp>
#include <sprout/complex/hash.hpp>
#include <sprout/complex/tuple.hpp>
#include <sprout/complex/container.hpp>
#include <sprout/complex/nearest.hpp>
#include <sprout/complex/udl.hpp>
#include <sprout/complex/type_traits.hpp>

View file

@ -9,6 +9,7 @@
#define SPROUT_COMPLEX_COMPLEX_HPP
#include <sprout/config.hpp>
#include <sprout/array/array.hpp>
namespace sprout {
template<typename T>
@ -27,100 +28,199 @@ namespace sprout {
//
template<typename T>
class complex {
private:
typedef sprout::array<T, 2> array_type;
public:
typedef T value_type;
typedef typename array_type::iterator iterator;
typedef typename array_type::const_iterator const_iterator;
typedef typename array_type::reference reference;
typedef typename array_type::const_reference const_reference;
typedef typename array_type::size_type size_type;
typedef typename array_type::pointer pointer;
typedef typename array_type::const_pointer const_pointer;
typedef typename array_type::pointer reverse_iterator;
typedef typename array_type::pointer const_reverse_iterator;
public:
SPROUT_STATIC_CONSTEXPR size_type static_size = array_type::static_size;
private:
T re_;
T im_;
array_type elems_;
public:
SPROUT_CONSTEXPR complex(T const& re = T(), T const& im = T()) SPROUT_NOEXCEPT
: re_(re), im_(im)
: elems_{{re, im}}
{}
complex(complex const&) = default;
SPROUT_CXX14_CONSTEXPR complex(complex const&) = default;
template<typename X>
SPROUT_CONSTEXPR complex(complex<X> const& other) SPROUT_NOEXCEPT
: re_(other.real()), im_(other.imag())
: elems_{{other.real(), other.imag()}}
{}
SPROUT_CONSTEXPR T const& real() const SPROUT_NOEXCEPT {
return re_;
return elems_[0];
}
SPROUT_CXX14_CONSTEXPR T& real() SPROUT_NOEXCEPT {
return re_;
return elems_[0];
}
SPROUT_CXX14_CONSTEXPR void real(T re) SPROUT_NOEXCEPT {
re_ = re;
elems_[0] = re;
}
SPROUT_CONSTEXPR T const& imag() const SPROUT_NOEXCEPT {
return im_;
return elems_[1];
}
SPROUT_CXX14_CONSTEXPR T& imag() SPROUT_NOEXCEPT {
return im_;
return elems_[1];
}
SPROUT_CXX14_CONSTEXPR void imag(T im) SPROUT_NOEXCEPT {
im_ = im;
elems_[1] = im;
}
SPROUT_CXX14_CONSTEXPR complex& operator=(T const& rhs) SPROUT_NOEXCEPT {
re_ = rhs;
im_ = T();
real() = rhs;
imag() = T();
return *this;
}
SPROUT_CXX14_CONSTEXPR complex& operator+=(T const& rhs) SPROUT_NOEXCEPT {
re_ += rhs;
real() += rhs;
return *this;
}
SPROUT_CXX14_CONSTEXPR complex& operator-=(T const& rhs) SPROUT_NOEXCEPT {
re_ -= rhs;
real() -= rhs;
return *this;
}
SPROUT_CXX14_CONSTEXPR complex& operator*=(T const& rhs) SPROUT_NOEXCEPT {
re_ *= rhs;
im_ *= rhs;
real() *= rhs;
imag() *= rhs;
return *this;
}
SPROUT_CXX14_CONSTEXPR complex& operator/=(T const& rhs) SPROUT_NOEXCEPT {
re_ /= rhs;
im_ /= rhs;
real() /= rhs;
imag() /= rhs;
return *this;
}
SPROUT_CXX14_CONSTEXPR complex& operator=(complex const& rhs) SPROUT_NOEXCEPT {
re_ = rhs.real();
im_ = rhs.imag();
real() = rhs.real();
imag() = rhs.imag();
return *this;
}
template<typename X>
SPROUT_CXX14_CONSTEXPR complex& operator=(complex<X> const& rhs) SPROUT_NOEXCEPT {
re_ = rhs.real();
im_ = rhs.imag();
real() = rhs.real();
imag() = rhs.imag();
return *this;
}
template<typename X>
SPROUT_CXX14_CONSTEXPR complex& operator+=(complex<X> const& rhs) SPROUT_NOEXCEPT {
re_ += rhs.real();
im_ += rhs.imag();
real() += rhs.real();
imag() += rhs.imag();
return *this;
}
template<typename X>
SPROUT_CXX14_CONSTEXPR complex& operator-=(complex<X> const& rhs) SPROUT_NOEXCEPT {
re_ -= rhs.real();
im_ -= rhs.imag();
real() -= rhs.real();
imag() -= rhs.imag();
return *this;
}
template<typename X>
SPROUT_CXX14_CONSTEXPR complex& operator*=(complex<X> const& rhs) SPROUT_NOEXCEPT {
return *this = complex(
re_ * rhs.real() - im_ * rhs.imag(),
re_ * rhs.imag() + im_ * rhs.real()
real() * rhs.real() - imag() * rhs.imag(),
real() * rhs.imag() + imag() * rhs.real()
);
}
template<typename X>
SPROUT_CXX14_CONSTEXPR complex& operator/=(complex<X> const& rhs) SPROUT_NOEXCEPT {
T n = sprout::detail::complex_norm(rhs);
return *this = complex(
(re_ * rhs.real() + im_ * rhs.imag()) / n,
(im_ * rhs.real() - re_ * rhs.imag()) / n
(real() * rhs.real() + imag() * rhs.imag()) / n,
(imag() * rhs.real() - real() * rhs.imag()) / n
);
}
// iterators:
SPROUT_CXX14_CONSTEXPR iterator begin() SPROUT_NOEXCEPT {
return elems_.begin();
}
SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT {
return elems_.begin();
}
SPROUT_CXX14_CONSTEXPR iterator end() SPROUT_NOEXCEPT {
return elems_.end();
}
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
return elems_.end();
}
SPROUT_CXX14_CONSTEXPR reverse_iterator rbegin() SPROUT_NOEXCEPT {
return elems_.rbegin();
}
SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT {
return elems_.rbegin();
}
SPROUT_CXX14_CONSTEXPR reverse_iterator rend() SPROUT_NOEXCEPT {
return elems_.rend();
}
SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT {
return elems_.rend();
}
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
return elems_.cbegin();
}
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
return elems_.cbegin();
}
SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT {
return elems_.crbegin();
}
SPROUT_CONSTEXPR const_reverse_iterator crend() const SPROUT_NOEXCEPT {
return elems_.crend();
}
// capacity:
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
return elems_.size();
}
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT {
return elems_.max_size();
}
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
return elems_.empty();
}
// element access:
SPROUT_CXX14_CONSTEXPR reference operator[](size_type i) {
return elems_[i];
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
return elems_[i];
}
SPROUT_CXX14_CONSTEXPR reference at(size_type i) {
return elems_.at(i);
}
SPROUT_CONSTEXPR const_reference at(size_type i) const {
return elems_.at(i);
}
SPROUT_CXX14_CONSTEXPR reference front() {
return elems_.front();
}
SPROUT_CONSTEXPR const_reference front() const {
return elems_.front();
}
SPROUT_CXX14_CONSTEXPR reference back() {
return elems_.back();
}
SPROUT_CONSTEXPR const_reference back() const {
return elems_.back();
}
SPROUT_CXX14_CONSTEXPR pointer data() SPROUT_NOEXCEPT {
return elems_.data();
}
SPROUT_CONSTEXPR const_pointer data() const SPROUT_NOEXCEPT {
return elems_.data();
}
SPROUT_CXX14_CONSTEXPR pointer c_array() SPROUT_NOEXCEPT {
return elems_.c_array();
}
SPROUT_CONSTEXPR const_pointer c_array() const SPROUT_NOEXCEPT {
return elems_.c_array();
}
};
template<typename T>
SPROUT_CONSTEXPR_OR_CONST typename sprout::complex<T>::size_type sprout::complex<T>::static_size;
} // namespace sprout
#endif // #ifndef SPROUT_COMPLEX_COMPLEX_HPP

View file

@ -0,0 +1,44 @@
/*=============================================================================
Copyright (c) 2011-2014 Bolero MURAKAMI
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)
=============================================================================*/
#ifndef SPROUT_COMPLEX_CONTAINER_HPP
#define SPROUT_COMPLEX_CONTAINER_HPP
#include <type_traits>
#include <sprout/utility/forward.hpp>
#include <sprout/complex/complex.hpp>
#include <sprout/container/traits.hpp>
namespace sprout {
//
// container_construct_traits
//
template<typename T>
struct container_construct_traits<sprout::complex<T> > {
public:
typedef sprout::complex<T> copied_type;
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type
deep_copy(Cont&& cont) {
return SPROUT_FORWARD(Cont, cont);
}
template<typename... Args>
static SPROUT_CONSTEXPR copied_type
make(Args&&... args) {
typedef sprout::detail::make_construct_impl<copied_type> impl_type;
return copied_type(SPROUT_FORWARD(Args, args)...);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type
remake(Cont&&, typename sprout::container_traits<sprout::complex<T> >::difference_type size, Args&&... args) {
return copied_type(SPROUT_FORWARD(Args, args)...);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_COMPLEX_CONTAINER_HPP

111
sprout/complex/tuple.hpp Normal file
View file

@ -0,0 +1,111 @@
/*=============================================================================
Copyright (c) 2011-2014 Bolero MURAKAMI
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)
=============================================================================*/
#ifndef SPROUT_COMPLEX_TUPLE_HPP
#define SPROUT_COMPLEX_TUPLE_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/complex/complex.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace tuples {
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
template<std::size_t I, typename T>
struct tuple_element_impl<I, sprout::complex<T> >
: public sprout::detail::nil_base
{};
template<typename T>
struct tuple_element_impl<0, sprout::complex<T> >
: public sprout::identity<T>
{};
template<typename T>
struct tuple_element_impl<1, sprout::complex<T> >
: public sprout::identity<T>
{};
template<std::size_t I, typename T>
struct get_impl;
template<typename T>
struct get_impl<0, sprout::complex<T> > {
public:
SPROUT_CONSTEXPR T& operator()(sprout::complex<T>& t) const {
return t.real();
}
SPROUT_CONSTEXPR T const& operator()(sprout::complex<T> const& t) const {
return t.real();
}
};
template<typename T>
struct get_impl<1, sprout::complex<T> > {
public:
SPROUT_CONSTEXPR T& operator()(sprout::complex<T>& t) const {
return t.imag();
}
SPROUT_CONSTEXPR T const& operator()(sprout::complex<T> const& t) const {
return t.imag();
}
};
} // namespace detail
} // namespace tuples
} // namespace sprout
namespace std {
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
//
// tuple_size
//
template<typename T>
struct tuple_size<sprout::complex<T> >
: public sprout::integral_constant<std::size_t, 2>
{};
//
// tuple_element
//
template<std::size_t I, typename T>
struct tuple_element<I, sprout::complex<T> >
: public sprout::tuples::detail::tuple_element_impl<I, sprout::complex<T> >
{};
#if defined(__clang__)
# pragma clang diagnostic pop
#endif
} // namespace std
namespace sprout {
//
// tuple_get
//
template<std::size_t I, typename T>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::complex<T> >::type&
tuple_get(sprout::complex<T>& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "tuple_get: index out of range");
return sprout::tuples::detail::get_impl<I, sprout::complex<T> >()(t);
}
template<std::size_t I, typename T>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::complex<T> >::type const&
tuple_get(sprout::complex<T> const& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "tuple_get: index out of range");
return sprout::tuples::detail::get_impl<I, sprout::complex<T> >()(t);
}
template<std::size_t I, typename T>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::complex<T> >::type&&
tuple_get(sprout::complex<T>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace sprout
#endif // #ifndef SPROUT_COMPLEX_TUPLE_HPP

View file

@ -19,44 +19,44 @@ namespace sprout {
namespace detail {
// Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/
template<typename IntType, typename CStrIterator>
template<typename IntType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR IntType
ascii_to_int_impl(CStrIterator str, IntType val, bool negative) {
ascii_to_int_impl(NullTerminatedIterator str, IntType val, bool negative) {
return !sprout::ascii::isdigit(*str)
? negative ? -val : val
: val > (sprout::numeric_limits<IntType>::max() - (*str - static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')) - (negative ? 1 : 0)) / 10
: val > (sprout::numeric_limits<IntType>::max() - (*str - static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('0')) - (negative ? 1 : 0)) / 10
? (negative ? sprout::numeric_limits<IntType>::min() : sprout::numeric_limits<IntType>::max())
: sprout::detail::ascii_to_int_impl<IntType>(
sprout::next(str),
val * 10 + (*str - static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')),
val * 10 + (*str - static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('0')),
negative
)
;
}
template<typename IntType, typename CStrIterator>
template<typename IntType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_unsigned<IntType>::value,
IntType
>::type
ascii_to_int(CStrIterator str) {
ascii_to_int(NullTerminatedIterator str) {
return sprout::ascii::isspace(*str)
? sprout::detail::ascii_to_int<IntType>(sprout::next(str))
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), false)
: sprout::detail::ascii_to_int_impl<IntType>(str, IntType(), false)
;
}
template<typename IntType, typename CStrIterator>
template<typename IntType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_signed<IntType>::value,
IntType
>::type
ascii_to_int(CStrIterator str) {
ascii_to_int(NullTerminatedIterator str) {
return sprout::ascii::isspace(*str)
? sprout::detail::ascii_to_int<IntType>(sprout::next(str))
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('-')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('-')
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), true)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), false)
: sprout::detail::ascii_to_int_impl<IntType>(str, IntType(), false)
;

View file

@ -19,10 +19,10 @@
namespace sprout {
namespace detail {
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_scale(
CStrIterator str,
NullTerminatedIterator str,
bool negative,
FloatType number = FloatType(),
std::size_t num_digits = 0,
@ -45,10 +45,10 @@ namespace sprout {
: number
;
}
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_exponent_2(
CStrIterator str,
NullTerminatedIterator str,
bool negative,
FloatType number = FloatType(),
std::size_t num_digits = 0,
@ -70,10 +70,10 @@ namespace sprout {
: HUGE_VAL
;
}
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_exponent_1(
CStrIterator str,
NullTerminatedIterator str,
bool negative,
FloatType number = FloatType(),
std::size_t num_digits = 0,
@ -82,7 +82,7 @@ namespace sprout {
long n = 0
)
{
typedef typename std::iterator_traits<CStrIterator>::value_type char_type;
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl_exponent_1<FloatType>(
sprout::next(str),
negative,
@ -102,10 +102,10 @@ namespace sprout {
)
;
}
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_exponent(
CStrIterator str,
NullTerminatedIterator str,
bool negative,
FloatType number = FloatType(),
std::size_t num_digits = 0,
@ -113,7 +113,7 @@ namespace sprout {
long exponent = 0
)
{
typedef typename std::iterator_traits<CStrIterator>::value_type char_type;
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
return (*str == static_cast<char_type>('e') || *str == static_cast<char_type>('E'))
? *sprout::next(str) == static_cast<char_type>('-')
? sprout::detail::str_to_float_impl_exponent_1<FloatType>(
@ -142,10 +142,10 @@ namespace sprout {
)
;
}
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_decimal_1(
CStrIterator str,
NullTerminatedIterator str,
bool negative,
FloatType number = FloatType(),
std::size_t num_digits = 0,
@ -164,10 +164,10 @@ namespace sprout {
)
;
}
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_decimal(
CStrIterator str,
NullTerminatedIterator str,
bool negative,
FloatType number = FloatType(),
std::size_t num_digits = 0,
@ -175,7 +175,7 @@ namespace sprout {
long exponent = 0
)
{
typedef typename std::iterator_traits<CStrIterator>::value_type char_type;
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl_decimal<FloatType>(
sprout::next(str),
negative,
@ -195,16 +195,16 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl(
CStrIterator str,
NullTerminatedIterator str,
bool negative,
FloatType number = FloatType(),
std::size_t num_digits = 0
)
{
typedef typename std::iterator_traits<CStrIterator>::value_type char_type;
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl<FloatType>(
sprout::next(str),
negative,
@ -225,21 +225,21 @@ namespace sprout {
)
;
}
template<typename FloatType, typename CStrIterator>
template<typename FloatType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR FloatType
str_to_float(CStrIterator str) {
str_to_float(NullTerminatedIterator str) {
return sprout::ascii::isspace(*str)
? sprout::detail::str_to_float<FloatType>(sprout::next(str))
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('-')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('-')
? sprout::detail::str_to_float_impl<FloatType>(sprout::next(str), true)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
? sprout::detail::str_to_float_impl<FloatType>(sprout::next(str), false)
: sprout::detail::str_to_float_impl<FloatType>(str, false)
;
}
template<typename FloatType, typename CStrIterator, typename CharPtr>
template<typename FloatType, typename NullTerminatedIterator, typename CharPtr>
inline SPROUT_CONSTEXPR FloatType
str_to_float(CStrIterator str, CharPtr* endptr) {
str_to_float(NullTerminatedIterator str, CharPtr* endptr) {
return !endptr ? sprout::detail::str_to_float<FloatType>(str)
#if defined(__MINGW32__)
: std::is_same<typename std::remove_cv<FloatType>::type, float>::value ? ::strtof(&*str, endptr)

View file

@ -24,9 +24,9 @@ namespace sprout {
namespace detail {
// Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/
template<typename IntType, typename CStrIterator>
template<typename IntType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR IntType
str_to_int_impl_1(CStrIterator str, int base, IntType val, IntType x, bool negative) {
str_to_int_impl_1(NullTerminatedIterator str, int base, IntType val, IntType x, bool negative) {
return x == static_cast<IntType>(-1) ? (negative ? -1 * val : val)
: val > (sprout::numeric_limits<IntType>::max() - x - (negative ? 1 : 0)) / base
? (negative ? sprout::numeric_limits<IntType>::min() : sprout::numeric_limits<IntType>::max())
@ -39,12 +39,12 @@ namespace sprout {
)
;
}
template<typename IntType, typename CStrIterator>
template<typename IntType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR IntType
str_to_int_impl(CStrIterator str, int base, bool negative) {
return *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')
? *sprout::next(str) == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('x')
|| *sprout::next(str) == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('X')
str_to_int_impl(NullTerminatedIterator str, int base, bool negative) {
return *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('0')
? *sprout::next(str) == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('x')
|| *sprout::next(str) == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('X')
? sprout::detail::str_to_int_impl_1<IntType>(
sprout::next(str, 2),
base ? base : 16,
@ -68,37 +68,37 @@ namespace sprout {
)
;
}
template<typename IntType, typename CStrIterator>
template<typename IntType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_unsigned<IntType>::value,
IntType
>::type
str_to_int(CStrIterator str, int base) {
str_to_int(NullTerminatedIterator str, int base) {
return sprout::ascii::isspace(*str)
? sprout::detail::str_to_int<IntType>(sprout::next(str), base)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
? sprout::detail::str_to_int_impl<IntType>(sprout::next(str), base, false)
: sprout::detail::str_to_int_impl<IntType>(str, base, false)
;
}
template<typename IntType, typename CStrIterator>
template<typename IntType, typename NullTerminatedIterator>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_signed<IntType>::value,
IntType
>::type
str_to_int(CStrIterator str, int base) {
str_to_int(NullTerminatedIterator str, int base) {
return sprout::ascii::isspace(*str)
? sprout::detail::str_to_int<IntType>(sprout::next(str), base)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('-')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('-')
? sprout::detail::str_to_int_impl<IntType>(sprout::next(str), base, true)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
? sprout::detail::str_to_int_impl<IntType>(sprout::next(str), base, false)
: sprout::detail::str_to_int_impl<IntType>(str, base, false)
;
}
template<typename IntType, typename CStrIterator, typename CharPtr>
template<typename IntType, typename NullTerminatedIterator, typename CharPtr>
inline SPROUT_CONSTEXPR IntType
str_to_int(CStrIterator str, CharPtr* endptr, int base) {
str_to_int(NullTerminatedIterator str, CharPtr* endptr, int base) {
return !endptr ? sprout::detail::str_to_int<IntType>(str, base)
#if defined(_MSC_VER)
: std::is_signed<IntType>::value

View file

@ -12,10 +12,10 @@
namespace sprout {
namespace detail {
template<typename OutputCStrIterator, typename CStrIterator>
inline SPROUT_CXX14_CONSTEXPR OutputCStrIterator
strcat(OutputCStrIterator s1, CStrIterator s2) {
OutputCStrIterator result = s1;
template<typename OutputNullTerminatedIterator, typename NullTerminatedIterator>
inline SPROUT_CXX14_CONSTEXPR OutputNullTerminatedIterator
strcat(OutputNullTerminatedIterator s1, NullTerminatedIterator s2) {
OutputNullTerminatedIterator result = s1;
while (*s1++)
;
while ((*s1++ = *s2++))

View file

@ -12,10 +12,10 @@
namespace sprout {
namespace detail {
template<typename OutputCStrIterator, typename CStrIterator>
inline SPROUT_CXX14_CONSTEXPR OutputCStrIterator
strcpy(OutputCStrIterator s1, CStrIterator s2) {
OutputCStrIterator result = s1;
template<typename OutputNullTerminatedIterator, typename NullTerminatedIterator>
inline SPROUT_CXX14_CONSTEXPR OutputNullTerminatedIterator
strcpy(OutputNullTerminatedIterator s1, NullTerminatedIterator s2) {
OutputNullTerminatedIterator result = s1;
while ((*s1++ = *s2++))
;
return result;

View file

@ -13,11 +13,11 @@
namespace sprout {
namespace detail {
template<typename OutputCStrIterator, typename CStrIterator>
inline SPROUT_CXX14_CONSTEXPR OutputCStrIterator
strncat(OutputCStrIterator s1, CStrIterator s2, std::size_t n) {
typedef typename std::iterator_traits<OutputCStrIterator>::value_type value_type;
OutputCStrIterator result = s1;
template<typename OutputNullTerminatedIterator, typename NullTerminatedIterator>
inline SPROUT_CXX14_CONSTEXPR OutputNullTerminatedIterator
strncat(OutputNullTerminatedIterator s1, NullTerminatedIterator s2, std::size_t n) {
typedef typename std::iterator_traits<OutputNullTerminatedIterator>::value_type value_type;
OutputNullTerminatedIterator result = s1;
while (*s1) {
++s1;
}

View file

@ -13,11 +13,11 @@
namespace sprout {
namespace detail {
template<typename OutputCStrIterator, typename CStrIterator>
inline SPROUT_CXX14_CONSTEXPR OutputCStrIterator
strncpy(OutputCStrIterator s1, CStrIterator s2, std::size_t n) {
typedef typename std::iterator_traits<OutputCStrIterator>::value_type value_type;
OutputCStrIterator result = s1;
template<typename OutputNullTerminatedIterator, typename NullTerminatedIterator>
inline SPROUT_CXX14_CONSTEXPR OutputNullTerminatedIterator
strncpy(OutputNullTerminatedIterator s1, NullTerminatedIterator s2, std::size_t n) {
typedef typename std::iterator_traits<OutputNullTerminatedIterator>::value_type value_type;
OutputNullTerminatedIterator result = s1;
while (n) {
--n;
if (!(*s1++ = *s2++)) {