fix coding-stype

This commit is contained in:
bolero-MURAKAMI 2012-10-06 00:58:56 +09:00
parent 2012838899
commit df3023db30
196 changed files with 2511 additions and 3946 deletions

View file

@ -25,7 +25,7 @@ namespace sprout {
};
} // namespace sprout
namespace sprout_adl {
namespace sprout {
//
// range_begin
//
@ -53,7 +53,7 @@ namespace sprout_adl {
range_end(sscrisk::cel::array<T, N> const& cont) {
return typename sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator(cont, cont.size());
}
} // namespace sprout_adl
} // namespace sprout
#endif
#endif // #ifndef SPROUT_ADAPT_SSCRISK_CEL_ARRAY_HPP

View file

@ -63,7 +63,9 @@ namespace sprout {
SPROUT_CONSTEXPR array fill(const_reference value) const {
return sprout::detail::array_fill_impl<array>(value, sprout::index_n<0, N>::make());
}
void swap(array<T, N>& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval<T&>(), std::declval<T&>()))) {
void swap(array<T, N>& other)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval<T&>(), std::declval<T&>())))
{
std::swap_ranges(other.begin(), other.end(), begin());
}
// iterators:
@ -208,7 +210,8 @@ namespace sprout {
// swap
//
template<typename T, std::size_t N>
inline void swap(sprout::array<T, N>& lhs, sprout::array<T, N>& rhs)
inline void
swap(sprout::array<T, N>& lhs, sprout::array<T, N>& rhs)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
{
lhs.swap(rhs);

View file

@ -16,27 +16,33 @@ namespace sprout {
// operator>=
//
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator==(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator==(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator!=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator!=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(lhs == rhs);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator<(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator<(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator>(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator>(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return rhs < lhs;
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator<=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator<=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(rhs < lhs);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator>=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator>=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(lhs < rhs);
}
} // namespace sprout

View file

@ -9,7 +9,7 @@
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout_adl {
namespace sprout {
//
// tuple_get
//
@ -30,7 +30,7 @@ namespace sprout_adl {
tuple_get(sprout::array<T, N>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace sprout_adl
} // namespace sprout
namespace std {
//

View file

@ -34,7 +34,8 @@ namespace sprout {
SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT;
private:
template <typename IntType>
SPROUT_CONSTEXPR IntType impl(IntType x, unsigned char i) const {
SPROUT_CONSTEXPR IntType
impl(IntType x, unsigned char i) const {
return bit_len_8_table[i]
? bit_len_8_table[i] + next_size * CHAR_BIT
: sprout::detail::bit_len<next_size>().template operator()(x)
@ -42,7 +43,8 @@ namespace sprout {
}
public:
template <typename IntType>
SPROUT_CONSTEXPR IntType operator()(IntType x) const {
SPROUT_CONSTEXPR IntType
operator()(IntType x) const {
return impl(x, static_cast<unsigned char>((x >> shift_bits) & UCHAR_MAX));
}
};
@ -50,7 +52,8 @@ namespace sprout {
struct bit_len<1> {
public:
template<typename IntType>
SPROUT_CONSTEXPR IntType operator()(IntType x) const {
SPROUT_CONSTEXPR IntType
operator()(IntType x) const {
return bit_len_8_table[static_cast<unsigned char>(x & UCHAR_MAX)];
}
};
@ -62,7 +65,8 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<IntType>::value,
IntType
>::type bit_length(IntType x) {
>::type
bit_length(IntType x) {
return sprout::detail::bit_len<sizeof(IntType)>().template operator()(x);
}
} // namespace sprout

View file

@ -31,7 +31,8 @@ namespace sprout {
SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT;
public:
template <typename IntType>
SPROUT_CONSTEXPR IntType operator()(IntType x) const {
SPROUT_CONSTEXPR IntType
operator()(IntType x) const {
return (sprout::detail::bit_rev<next_size>().template operator()(x) << shift_bits)
| (sprout::detail::bit_rev<next_size>().template operator()(x >> shift_bits))
;
@ -41,7 +42,8 @@ namespace sprout {
struct bit_rev<1> {
public:
template<typename IntType>
SPROUT_CONSTEXPR IntType operator()(IntType x) const {
SPROUT_CONSTEXPR IntType
operator()(IntType x) const {
return sprout::detail::bit_rev_8_table[static_cast<unsigned char>(x & UCHAR_MAX)];
}
};
@ -53,7 +55,8 @@ namespace sprout {
SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<IntType>::value,
IntType
>::type bit_reverse(IntType x) {
>::type
bit_reverse(IntType x) {
typedef typename std::make_unsigned<IntType>::type unsigned_type;
return static_cast<IntType>(
sprout::detail::bit_rev<sizeof(IntType)>().template operator()<unsigned_type>(x)
@ -66,7 +69,8 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<IntType>::value,
IntType
>::type bit_reverse_in(IntType x, std::size_t length) {
>::type
bit_reverse_in(IntType x, std::size_t length) {
typedef typename std::make_unsigned<IntType>::type unsigned_type;
return length <= sizeof(IntType) * CHAR_BIT
? static_cast<IntType>(

View file

@ -7,7 +7,8 @@
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
inline SPROUT_CONSTEXPR std::intmax_t imaxabs(std::intmax_t j) {
inline SPROUT_CONSTEXPR std::intmax_t
imaxabs(std::intmax_t j) {
return j < 0 ? -j : j;
}
} // namespace sprout

View file

@ -32,7 +32,8 @@ namespace sprout {
sprout::detail::div_t_traits2<T>::offsetof_quot == 0
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2<T>::type div_impl2(T const& numer, T const& denom) {
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2<T>::type
div_impl2(T const& numer, T const& denom) {
return {numer / denom, numer % denom};
}
@ -42,12 +43,14 @@ namespace sprout {
sprout::detail::div_t_traits2<T>::offsetof_rem == 0
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2<T>::type div_impl2(T const &numer, T const& denom) {
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2<T>::type
div_impl2(T const &numer, T const& denom) {
return {numer % denom, numer / denom};
}
} // namespace detail
SPROUT_CONSTEXPR std::imaxdiv_t imaxdiv(std::intmax_t numer, std::intmax_t denom) {
inline SPROUT_CONSTEXPR std::imaxdiv_t
imaxdiv(std::intmax_t numer, std::intmax_t denom) {
return sprout::detail::div_impl2(numer, denom);
}
@ -55,7 +58,8 @@ namespace sprout {
typename T,
typename sprout::enabler_if<std::is_same<T, std::intmax_t>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR std::imaxdiv_t div(T numer, T denom) {
inline SPROUT_CONSTEXPR std::imaxdiv_t
div(T numer, T denom) {
return sprout::imaxdiv(numer, denom);
}
} // namespace sprout

View file

@ -10,19 +10,23 @@ namespace sprout {
//
// strtoimax
//
inline SPROUT_CONSTEXPR std::intmax_t strtoimax(char const* str, char** endptr, int base = 10){
inline SPROUT_CONSTEXPR std::intmax_t
strtoimax(char const* str, char** endptr, int base = 10) {
return sprout::str_to_int<std::intmax_t>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR std::intmax_t strtoimax(Char const* str, Char** endptr, int base = 10){
inline SPROUT_CONSTEXPR std::intmax_t
strtoimax(Char const* str, Char** endptr, int base = 10) {
return sprout::str_to_int<std::intmax_t>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR std::intmax_t strtoimax(Char const* str, std::nullptr_t endptr, int base = 10){
inline SPROUT_CONSTEXPR std::intmax_t
strtoimax(Char const* str, std::nullptr_t endptr, int base = 10) {
return sprout::str_to_int<std::intmax_t>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR std::intmax_t strtoimax(Char const* str, int base = 10){
inline SPROUT_CONSTEXPR std::intmax_t
strtoimax(Char const* str, int base = 10) {
return sprout::str_to_int<std::intmax_t>(str, base);
}
} // namespace sprout

View file

@ -10,19 +10,23 @@ namespace sprout {
//
// strtoumax
//
inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(char const* str, char** endptr, int base = 10){
inline SPROUT_CONSTEXPR std::uintmax_t
strtoumax(char const* str, char** endptr, int base = 10) {
return sprout::str_to_int<std::uintmax_t>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(Char const* str, Char** endptr, int base = 10){
inline SPROUT_CONSTEXPR std::uintmax_t
strtoumax(Char const* str, Char** endptr, int base = 10) {
return sprout::str_to_int<std::uintmax_t>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(Char const* str, std::nullptr_t endptr, int base = 10){
inline SPROUT_CONSTEXPR std::uintmax_t
strtoumax(Char const* str, std::nullptr_t endptr, int base = 10) {
return sprout::str_to_int<std::uintmax_t>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(Char const* str, int base = 10){
inline SPROUT_CONSTEXPR std::uintmax_t
strtoumax(Char const* str, int base = 10) {
return sprout::str_to_int<std::uintmax_t>(str, base);
}
} // namespace sprout

View file

@ -1,588 +1,12 @@
#ifndef SPROUT_COMPLEX_HPP
#define SPROUT_COMPLEX_HPP
#include <iosfwd>
#include <ios>
#include <sprout/config.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/math/abs.hpp>
#include <sprout/math/sin.hpp>
#include <sprout/math/cos.hpp>
#include <sprout/math/atan2.hpp>
#include <sprout/math/sinh.hpp>
#include <sprout/math/cosh.hpp>
#include <sprout/math/exp.hpp>
#include <sprout/math/log.hpp>
#include <sprout/math/pow.hpp>
#include <sprout/math/sqrt.hpp>
#include <sprout/math/ceil.hpp>
#include <sprout/math/floor.hpp>
#include <sprout/math/trunc.hpp>
#include <sprout/math/round.hpp>
namespace sprout {
template<typename T>
class complex;
template<typename T>
SPROUT_CONSTEXPR T norm(sprout::complex<T> const& x);
//
// complex
//
template<typename T>
class complex {
public:
typedef T value_type;
private:
T re_;
T im_;
public:
SPROUT_CONSTEXPR complex(T const& re = T(), T const& im = T())
: re_(re)
, im_(im)
{}
SPROUT_CONSTEXPR complex(complex const&) = default;
template<typename X>
SPROUT_CONSTEXPR complex(complex<X> const& other)
: re_(other.real())
, im_(other.imag())
{}
SPROUT_CONSTEXPR T real() const {
return re_;
}
void real(T re) {
re_ = re;
}
SPROUT_CONSTEXPR T imag() const{
return im_;
}
void imag(T im) {
im_ = im;
}
complex<T>& operator=(T const& rhs) {
re_ = rhs;
im_ = T();
return *this;
}
complex<T>& operator+=(T const& rhs) {
re_ += rhs;
return *this;
}
complex<T>& operator-=(T const& rhs) {
re_ -= rhs;
return *this;
}
complex<T>& operator*=(T const& rhs) {
re_ *= rhs;
im_ *= rhs;
return *this;
}
complex<T>& operator/=(T const& rhs) {
re_ /= rhs;
im_ /= rhs;
return *this;
}
complex& operator=(complex const&) = default;
template<typename X>
complex<T>& operator=(complex<X> const& rhs) {
re_ = rhs.real();
im_ = rhs.imag();
return *this;
}
template<typename X>
complex<T>& operator+=(complex<X> const& rhs) {
re_ += rhs.real();
im_ += rhs.imag();
return *this;
}
template<typename X>
complex<T>& operator-=(complex<X> const& rhs) {
re_ -= rhs.real();
im_ -= rhs.imag();
return *this;
}
template<typename X>
complex<T>& operator*=(complex<X> const& rhs) {
return *this = complex<T>(
re_ * rhs.real() - im_ * rhs.imag(),
re_ * rhs.imag() + im_ * rhs.real()
);
}
template<typename X>
complex<T>& operator/=(complex<X> const& rhs) {
T n = sprout::norm(rhs);
return *this = complex<T>(
(re_ * rhs.real() + im_ * rhs.imag()) / n,
(im_ * rhs.real() - re_ * rhs.imag()) / n
);
}
};
// 26.4.6, operators:
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs.real() + rhs.real(),
lhs.imag() + rhs.imag()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() + rhs,
lhs.imag()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs + rhs.real(),
rhs.imag()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs.real() - rhs.real(),
lhs.imag() - rhs.imag()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() - rhs,
lhs.imag()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs - rhs.real(),
-rhs.imag()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator*(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs.real() * rhs.real() - lhs.imag() * rhs.imag(),
lhs.real() * rhs.imag() + lhs.imag() * rhs.real()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator*(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() * rhs,
lhs.imag() * rhs
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator*(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs * rhs.real(),
lhs * rhs.imag()
);
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> divides_impl(
sprout::complex<T> const& lhs,
sprout::complex<T> const& rhs,
T const& n
)
{
return sprout::complex<T>(
(lhs.real() * rhs.real() + lhs.imag() * rhs.imag()) / n,
(lhs.imag() * rhs.real() - lhs.real() * rhs.imag()) / n
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> divides_impl(
T const& lhs,
sprout::complex<T> const& rhs,
T const& n
)
{
return sprout::complex<T>(
lhs * rhs.real() / n,
-lhs * rhs.imag() / n
);
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator/(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::detail::divides_impl(lhs, rhs, sprout::norm(rhs));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator/(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() / rhs,
lhs.imag() / rhs
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator/(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::detail::divides_impl(lhs, rhs, sprout::norm(rhs));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(sprout::complex<T> const& x) {
return x;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(sprout::complex<T> const& x) {
return sprout::complex<T>(-x.real(), -x.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator==(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return lhs.real() == rhs.real() && lhs.imag() == rhs.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator==(sprout::complex<T> const& lhs, T const& rhs) {
return lhs.real() == rhs && lhs.imag() == T();
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator==(T const& lhs, sprout::complex<T> const& rhs) {
return lhs == rhs.real() && T() == rhs.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator!=(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return !(lhs == rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator!=(sprout::complex<T> const& lhs, T const& rhs) {
return !(lhs == rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator!=(T const& lhs, sprout::complex<T> const& rhs) {
return !(lhs == rhs);
}
template<typename T, typename Char, typename Traits>
std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& lhs, sprout::complex<T>& rhs) {
T re, im;
Char ch;
lhs >> ch;
if (ch == '(') {
lhs >> re >> ch;
if (ch == ',') {
lhs >> im >> ch;
if (ch == ')') {
rhs = sprout::complex<T>(re, im);
} else {
lhs.setstate(std::ios_base::failbit);
}
} else if (ch == ')') {
rhs = re;
} else {
lhs.setstate(std::ios_base::failbit);
}
} else {
lhs.putback(ch);
lhs >> re;
rhs = re;
}
return lhs;
}
template<typename T, typename Char, typename Traits>
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& lhs, sprout::complex<T> const& rhs) {
return lhs << '(' << rhs.real() << ',' << rhs.imag() << ')';
}
// 26.4.7, values:
template<typename T>
inline SPROUT_CONSTEXPR T real(sprout::complex<T> const& x) {
return x.real();
}
template<typename T>
inline SPROUT_CONSTEXPR T imag(sprout::complex<T> const& x) {
return x.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR T abs(sprout::complex<T> const& x) {
return sprout::sqrt(sprout::norm(x));
}
template<typename T>
inline SPROUT_CONSTEXPR T arg(sprout::complex<T> const& x) {
return sprout::atan2(x.imag(), x.real());
}
template<typename T>
inline SPROUT_CONSTEXPR T norm(sprout::complex<T> const& x) {
return x.real() * x.real() + x.imag() * x.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> conj(sprout::complex<T> const& x) {
return sprout::complex<T>(x.real(), -x.imag());
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> proj_impl(sprout::complex<T> const& x, T const& den) {
return sprout::complex<T>(
T(2) * x.real() / den,
T(2) * x.imag() / den
);
}
} // detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> proj(sprout::complex<T> const& x) {
return sprout::detail::proj_impl(
x,
sprout::norm(x) + T(1)
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> polar(T const& rho, T const& theta = 0) {
return sprout::complex<T>(rho * sprout::cos(theta), rho * sprout::sin(theta));
}
// 26.4.8, transcendentals:
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> acos(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> asin(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> atan(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> acosh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> asinh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> atanh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> cos(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> cosh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> exp(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> log(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> log10(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, T const& y);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, sprout::complex<T> const& y);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow(T const& x, sprout::complex<T> const& y);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sin(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sinh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sqrt(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> tan(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> tanh(sprout::complex<T> const& x);
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> acos_impl(sprout::complex<T> const& t) {
return sprout::complex<T>(sprout::math::half_pi<T>() - t.real(), -t.imag());
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> acos(sprout::complex<T> const& x) {
return sprout::detail::acos_impl(sprout::asin(x));
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> asin_impl(sprout::complex<T> const& t) {
return sprout::complex<T>(t.imag(), -t.real());
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> asin(sprout::complex<T> const& x) {
return sprout::detail::asin_impl(sprout::asinh(sprout::complex<T>(-x.imag(), x.real())));
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atan_impl_1(
sprout::complex<T> const& x,
T const& r2,
T const& z,
T const& num,
T const& den
)
{
return sprout::complex<T>(
T(0.5) * sprout::atan2(T(2) * x.real(), z),
T(0.25) * sprout::log((r2 + num * num) / (r2 + den * den))
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atan_impl(
sprout::complex<T> const& x,
T const& r2
)
{
return sprout::detail::atan_impl_1(
x,
r2,
T(1) - r2 - x.imag() * x.imag(),
x.imag() + T(1),
x.imag() - T(1)
);
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atan(sprout::complex<T> const& x) {
return sprout::detail::atan_impl(x, x.real() * x.real());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> acosh(sprout::complex<T> const& x) {
return T(2) * sprout::log(sprout::sqrt(T(0.5) * (x + T(1))) + sprout::sqrt(T(0.5) * (x - T(1))));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> asinh(sprout::complex<T> const& x) {
return sprout::log(
sprout::sqrt(
sprout::complex<T>(
(x.real() - x.imag()) * (x.real() + x.imag()) + T(1),
T(2) * x.real() * x.imag()
)
)
+ x
);
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atanh_impl_1(
sprout::complex<T> const& x,
T const& i2,
T const& z,
T const& num,
T const& den
)
{
return sprout::complex<T>(
T(0.25) * (sprout::log(i2 + num * num) - sprout::log(i2 + den * den)),
T(0.5) * sprout::atan2(T(2) * x.imag(), z)
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atanh_impl(
sprout::complex<T> const& x,
T const& i2
)
{
return sprout::detail::atanh_impl_1(
x,
i2,
T(1) - i2 - x.real() * x.real(),
T(1) + x.imag(),
T(1) - x.imag()
);
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atanh(sprout::complex<T> const& x) {
return sprout::detail::atanh_impl(x, x.imag() * x.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> cos(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::cos(x.real()) * sprout::cosh(x.imag()),
-(sprout::sin(x.real()) * sprout::sinh(x.imag()))
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> cosh(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::cosh(x.real()) * sprout::cos(x.imag()),
sprout::sinh(x.real()) * sprout::sin(x.imag())
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> exp(sprout::complex<T> const& x) {
return sprout::polar(sprout::exp(x.real()), x.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> log(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::log(sprout::abs(x)), sprout::arg(x));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> log10(sprout::complex<T> const& x) {
return sprout::log(x) / sprout::log(T(10));
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> pow_impl(sprout::complex<T> const& t, T const& y) {
return sprout::polar(sprout::exp(y * t.real()), y * t.imag());
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, T const& y) {
return x == T() ? T()
: x.imag() == T() && x.real() > T() ? sprout::pow(x.real(), y)
: sprout::detail::pow_impl(sprout::log(x), y)
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, sprout::complex<T> const& y) {
return x == T() ? T()
: sprout::exp(y * sprout::log(x))
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> pow(T const& x, sprout::complex<T> const& y) {
return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * sprout::log(x))
: sprout::pow(sprout::complex<T>(x), y)
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sin(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::sin(x.real()) * sprout::cosh(x.imag()),
sprout::cos(x.real()) * sprout::sinh(x.imag())
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sinh(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::sinh(x.real()) * sprout::cos(x.imag()),
sprout::cosh(x.real()) * sprout::sin(x.imag())
);
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt_impl_1(sprout::complex<T> const& x, T const& t) {
return sprout::complex<T>(t, x.imag() < T() ? -t : t);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt_impl_2_1(sprout::complex<T> const& x, T const& t, T const& u) {
return x.real() > T() ? sprout::complex<T>(u, x.imag() / t)
: sprout::complex<T>(sprout::abs(x.imag()) / t, x.imag() < T() ? -u : u)
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt_impl_2(sprout::complex<T> const& x, T const& t) {
return sprout::detail::sqrt_impl_2_1(x, t, t / 2);
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt(sprout::complex<T> const& x) {
return x.real() == T() ? sprout::detail::sqrt_impl_1(x, sprout::sqrt(abs(x.imag()) / 2))
: sprout::detail::sqrt_impl_2(x, sprout::sqrt(2 * (sprout::abs(x) + sprout::abs(x.real()))))
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> tan(sprout::complex<T> const& x) {
return sprout::sin(x) / sprout::cos(x);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> tanh(sprout::complex<T> const& x) {
return sprout::sinh(x) / sprout::cosh(x);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> ceil(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::ceil(x.real()), sprout::ceil(x.imag()));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> floor(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::floor(x.real()), sprout::floor(x.imag()));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> trunc(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::trunc(x.real()), sprout::trunc(x.imag()));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> round(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::round(x.real()), sprout::round(x.imag()));
}
} // namespace sprout
#include <sprout/complex/complex.hpp>
#include <sprout/complex/operators.hpp>
#include <sprout/complex/values.hpp>
#include <sprout/complex/transcendentals.hpp>
#include <sprout/complex/hash.hpp>
#include <sprout/complex/nearest.hpp>
#endif // #ifndef SPROUT_COMPLEX_HPP

View file

@ -9,7 +9,8 @@ namespace sprout {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T complex_norm(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR T
complex_norm(sprout::complex<T> const& x) {
return x.real() * x.real() + x.imag() * x.imag();
}
} // namespace detail
@ -47,59 +48,59 @@ namespace sprout {
void imag(T im) {
im_ = im;
}
complex<T>& operator=(T const& rhs) {
complex& operator=(T const& rhs) {
re_ = rhs;
im_ = T();
return *this;
}
complex<T>& operator+=(T const& rhs) {
complex& operator+=(T const& rhs) {
re_ += rhs;
return *this;
}
complex<T>& operator-=(T const& rhs) {
complex& operator-=(T const& rhs) {
re_ -= rhs;
return *this;
}
complex<T>& operator*=(T const& rhs) {
complex& operator*=(T const& rhs) {
re_ *= rhs;
im_ *= rhs;
return *this;
}
complex<T>& operator/=(T const& rhs) {
complex& operator/=(T const& rhs) {
re_ /= rhs;
im_ /= rhs;
return *this;
}
complex& operator=(complex const&) = default;
template<typename X>
complex<T>& operator=(complex<X> const& rhs) {
complex& operator=(complex<X> const& rhs) {
re_ = rhs.real();
im_ = rhs.imag();
return *this;
}
template<typename X>
complex<T>& operator+=(complex<X> const& rhs) {
complex& operator+=(complex<X> const& rhs) {
re_ += rhs.real();
im_ += rhs.imag();
return *this;
}
template<typename X>
complex<T>& operator-=(complex<X> const& rhs) {
complex& operator-=(complex<X> const& rhs) {
re_ -= rhs.real();
im_ -= rhs.imag();
return *this;
}
template<typename X>
complex<T>& operator*=(complex<X> const& rhs) {
return *this = complex<T>(
complex& operator*=(complex<X> const& rhs) {
return *this = complex(
re_ * rhs.real() - im_ * rhs.imag(),
re_ * rhs.imag() + im_ * rhs.real()
);
}
template<typename X>
complex<T>& operator/=(complex<X> const& rhs) {
complex& operator/=(complex<X> const& rhs) {
T n = sprout::detail::complex_norm(rhs);
return *this = complex<T>(
return *this = complex(
(re_ * rhs.real() + im_ * rhs.imag()) / n,
(im_ * rhs.real() - re_ * rhs.imag()) / n
);

View file

@ -11,7 +11,8 @@ namespace sprout {
// hash_value
//
template<typename T>
inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::complex<T> const& v) {
inline SPROUT_CONSTEXPR std::size_t
hash_value(sprout::complex<T> const& v) {
return sprout::hash_values(v.real(), v.imag());
}
} // namespace sprout

View file

@ -10,19 +10,23 @@
namespace sprout {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> ceil(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
ceil(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::ceil(x.real()), sprout::ceil(x.imag()));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> floor(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
floor(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::floor(x.real()), sprout::floor(x.imag()));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> trunc(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
trunc(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::trunc(x.real()), sprout::trunc(x.imag()));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> round(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
round(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::round(x.real()), sprout::round(x.imag()));
}
} // namespace sprout

View file

@ -9,143 +9,126 @@
namespace sprout {
// 26.4.6, operators:
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs.real() + rhs.real(),
lhs.imag() + rhs.imag()
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator+(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(lhs.real() + rhs.real(), lhs.imag() + rhs.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() + rhs,
lhs.imag()
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator+(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(lhs.real() + rhs, lhs.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs + rhs.real(),
rhs.imag()
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator+(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(lhs + rhs.real(), rhs.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs.real() - rhs.real(),
lhs.imag() - rhs.imag()
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator-(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(lhs.real() - rhs.real(), lhs.imag() - rhs.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() - rhs,
lhs.imag()
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator-(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(lhs.real() - rhs, lhs.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs - rhs.real(),
-rhs.imag()
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator-(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(lhs - rhs.real(), -rhs.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator*(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
inline SPROUT_CONSTEXPR sprout::complex<T>
operator*(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs.real() * rhs.real() - lhs.imag() * rhs.imag(),
lhs.real() * rhs.imag() + lhs.imag() * rhs.real()
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator*(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() * rhs,
lhs.imag() * rhs
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator*(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(lhs.real() * rhs, lhs.imag() * rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator*(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(
lhs * rhs.real(),
lhs * rhs.imag()
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator*(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::complex<T>(lhs * rhs.real(), lhs * rhs.imag());
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> divides_impl(
sprout::complex<T> const& lhs,
sprout::complex<T> const& rhs,
T const& n
)
{
inline SPROUT_CONSTEXPR sprout::complex<T>
divides_impl(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs, T const& n) {
return sprout::complex<T>(
(lhs.real() * rhs.real() + lhs.imag() * rhs.imag()) / n,
(lhs.imag() * rhs.real() - lhs.real() * rhs.imag()) / n
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> divides_impl(
T const& lhs,
sprout::complex<T> const& rhs,
T const& n
)
{
return sprout::complex<T>(
lhs * rhs.real() / n,
-lhs * rhs.imag() / n
);
inline SPROUT_CONSTEXPR sprout::complex<T>
divides_impl(T const& lhs, sprout::complex<T> const& rhs, T const& n) {
return sprout::complex<T>(lhs * rhs.real() / n, -lhs * rhs.imag() / n);
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator/(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
inline SPROUT_CONSTEXPR sprout::complex<T>
operator/(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return sprout::detail::divides_impl(lhs, rhs, sprout::detail::complex_norm(rhs));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator/(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(
lhs.real() / rhs,
lhs.imag() / rhs
);
inline SPROUT_CONSTEXPR sprout::complex<T>
operator/(sprout::complex<T> const& lhs, T const& rhs) {
return sprout::complex<T>(lhs.real() / rhs, lhs.imag() / rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator/(T const& lhs, sprout::complex<T> const& rhs) {
inline SPROUT_CONSTEXPR sprout::complex<T>
operator/(T const& lhs, sprout::complex<T> const& rhs) {
return sprout::detail::divides_impl(lhs, rhs, sprout::detail::complex_norm(rhs));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator+(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
operator+(sprout::complex<T> const& x) {
return x;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> operator-(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
operator-(sprout::complex<T> const& x) {
return sprout::complex<T>(-x.real(), -x.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator==(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator==(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return lhs.real() == rhs.real() && lhs.imag() == rhs.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator==(sprout::complex<T> const& lhs, T const& rhs) {
inline SPROUT_CONSTEXPR bool
operator==(sprout::complex<T> const& lhs, T const& rhs) {
return lhs.real() == rhs && lhs.imag() == T();
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator==(T const& lhs, sprout::complex<T> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator==(T const& lhs, sprout::complex<T> const& rhs) {
return lhs == rhs.real() && T() == rhs.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator!=(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator!=(sprout::complex<T> const& lhs, sprout::complex<T> const& rhs) {
return !(lhs == rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator!=(sprout::complex<T> const& lhs, T const& rhs) {
inline SPROUT_CONSTEXPR bool
operator!=(sprout::complex<T> const& lhs, T const& rhs) {
return !(lhs == rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR bool operator!=(T const& lhs, sprout::complex<T> const& rhs) {
inline SPROUT_CONSTEXPR bool
operator!=(T const& lhs, sprout::complex<T> const& rhs) {
return !(lhs == rhs);
}
template<typename T, typename Char, typename Traits>
std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& lhs, sprout::complex<T>& rhs) {
std::basic_istream<Char, Traits>&
operator>>(std::basic_istream<Char, Traits>& lhs, sprout::complex<T>& rhs) {
T re, im;
Char ch;
lhs >> ch;
@ -171,7 +154,8 @@ namespace sprout {
return lhs;
}
template<typename T, typename Char, typename Traits>
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& lhs, sprout::complex<T> const& rhs) {
std::basic_ostream<Char, Traits>&
operator<<(std::basic_ostream<Char, Traits>& lhs, sprout::complex<T> const& rhs) {
return lhs << '(' << rhs.real() << ',' << rhs.imag() << ')';
}
} // namespace sprout

View file

@ -20,103 +20,130 @@
namespace sprout {
// 26.4.8, transcendentals:
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> acos(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
acos(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> asin(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
asin(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> atan(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
atan(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> acosh(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
acosh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> asinh(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
asinh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> atanh(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
atanh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> cos(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
cos(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> cosh(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
cosh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> exp(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
exp(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> log(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
log(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> log10(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
log10(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, T const& y);
SPROUT_CONSTEXPR sprout::complex<T>
pow(sprout::complex<T> const& x, T const& y);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, sprout::complex<T> const& y);
SPROUT_CONSTEXPR sprout::complex<T>
pow(sprout::complex<T> const& x, sprout::complex<T> const& y);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow(T const& x, sprout::complex<T> const& y);
SPROUT_CONSTEXPR sprout::complex<T>
pow(T const& x, sprout::complex<T> const& y);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sin(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
sin(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sinh(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
sinh(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sqrt(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
sqrt(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> tan(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
tan(sprout::complex<T> const& x);
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> tanh(sprout::complex<T> const& x);
SPROUT_CONSTEXPR sprout::complex<T>
tanh(sprout::complex<T> const& x);
//
// acos
// asin
// atan
//
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> acos_impl(sprout::complex<T> const& t) {
inline SPROUT_CONSTEXPR sprout::complex<T>
acos_impl(sprout::complex<T> const& t) {
return sprout::complex<T>(sprout::math::half_pi<T>() - t.real(), -t.imag());
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> acos(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
acos(sprout::complex<T> const& x) {
return sprout::detail::acos_impl(sprout::asin(x));
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> asin_impl(sprout::complex<T> const& t) {
inline SPROUT_CONSTEXPR sprout::complex<T>
asin_impl(sprout::complex<T> const& t) {
return sprout::complex<T>(t.imag(), -t.real());
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> asin(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
asin(sprout::complex<T> const& x) {
return sprout::detail::asin_impl(sprout::asinh(sprout::complex<T>(-x.imag(), x.real())));
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atan_impl_1(
sprout::complex<T> const& x,
T const& r2,
T const& z,
T const& num,
T const& den
)
{
inline SPROUT_CONSTEXPR sprout::complex<T>
atan_impl_1(sprout::complex<T> const& x, T const& r2, T const& z, T const& num, T const& den) {
return sprout::complex<T>(
T(0.5) * sprout::atan2(T(2) * x.real(), z),
T(0.25) * sprout::log((r2 + num * num) / (r2 + den * den))
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atan_impl(
sprout::complex<T> const& x,
T const& r2
)
{
inline SPROUT_CONSTEXPR sprout::complex<T>
atan_impl(sprout::complex<T> const& x, T const& r2) {
return sprout::detail::atan_impl_1(
x,
r2,
x, r2,
T(1) - r2 - x.imag() * x.imag(),
x.imag() + T(1),
x.imag() - T(1)
x.imag() + T(1), x.imag() - T(1)
);
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atan(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
atan(sprout::complex<T> const& x) {
return sprout::detail::atan_impl(x, x.real() * x.real());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> acosh(sprout::complex<T> const& x) {
//
// acosh
// asinh
// atanh
//
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T>
acosh(sprout::complex<T> const& x) {
return T(2) * sprout::log(sprout::sqrt(T(0.5) * (x + T(1))) + sprout::sqrt(T(0.5) * (x - T(1))));
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> asinh(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
asinh(sprout::complex<T> const& x) {
return sprout::log(
sprout::sqrt(
sprout::complex<T>(
@ -129,58 +156,63 @@ namespace sprout {
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atanh_impl_1(
sprout::complex<T> const& x,
T const& i2,
T const& z,
T const& num,
T const& den
)
{
inline SPROUT_CONSTEXPR sprout::complex<T>
atanh_impl_1(sprout::complex<T> const& x, T const& i2, T const& z, T const& num, T const& den) {
return sprout::complex<T>(
T(0.25) * (sprout::log(i2 + num * num) - sprout::log(i2 + den * den)),
T(0.5) * sprout::atan2(T(2) * x.imag(), z)
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atanh_impl(
sprout::complex<T> const& x,
T const& i2
)
{
inline SPROUT_CONSTEXPR sprout::complex<T>
atanh_impl(sprout::complex<T> const& x, T const& i2) {
return sprout::detail::atanh_impl_1(
x,
i2,
x, i2,
T(1) - i2 - x.real() * x.real(),
T(1) + x.imag(),
T(1) - x.imag()
T(1) + x.imag(), T(1) - x.imag()
);
}
} // namespace detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> atanh(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
atanh(sprout::complex<T> const& x) {
return sprout::detail::atanh_impl(x, x.imag() * x.imag());
}
//
// cos
// cosh
//
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> cos(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
cos(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::cos(x.real()) * sprout::cosh(x.imag()),
-(sprout::sin(x.real()) * sprout::sinh(x.imag()))
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> cosh(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
cosh(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::cosh(x.real()) * sprout::cos(x.imag()),
sprout::sinh(x.real()) * sprout::sin(x.imag())
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> exp(sprout::complex<T> const& x) {
//
// exp
// log
// log10
//
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T>
exp(sprout::complex<T> const& x) {
return sprout::polar(sprout::exp(x.real()), x.imag());
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> log(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
log(sprout::complex<T> const& x) {
return sprout::complex<T>(sprout::log(sprout::abs(x)), sprout::arg(x));
}
template<typename T>
@ -193,67 +225,96 @@ namespace sprout {
return sprout::polar(sprout::exp(y * t.real()), y * t.imag());
}
} // namespace detail
//
// pow
//
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, T const& y) {
inline SPROUT_CONSTEXPR sprout::complex<T>
pow(sprout::complex<T> const& x, T const& y) {
return x == T() ? T()
: x.imag() == T() && x.real() > T() ? sprout::pow(x.real(), y)
: sprout::detail::pow_impl(sprout::log(x), y)
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, sprout::complex<T> const& y) {
inline SPROUT_CONSTEXPR sprout::complex<T>
pow(sprout::complex<T> const& x, sprout::complex<T> const& y) {
return x == T() ? T()
: sprout::exp(y * sprout::log(x))
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> pow(T const& x, sprout::complex<T> const& y) {
inline SPROUT_CONSTEXPR sprout::complex<T>
pow(T const& x, sprout::complex<T> const& y) {
return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * sprout::log(x))
: sprout::pow(sprout::complex<T>(x), y)
;
}
//
// sin
// sinh
//
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sin(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
sin(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::sin(x.real()) * sprout::cosh(x.imag()),
sprout::cos(x.real()) * sprout::sinh(x.imag())
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sinh(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
sinh(sprout::complex<T> const& x) {
return sprout::complex<T>(
sprout::sinh(x.real()) * sprout::cos(x.imag()),
sprout::cosh(x.real()) * sprout::sin(x.imag())
);
}
//
// sqrt
//
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt_impl_1(sprout::complex<T> const& x, T const& t) {
inline SPROUT_CONSTEXPR sprout::complex<T>
sqrt_impl_1(sprout::complex<T> const& x, T const& t) {
return sprout::complex<T>(t, x.imag() < T() ? -t : t);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt_impl_2_1(sprout::complex<T> const& x, T const& t, T const& u) {
inline SPROUT_CONSTEXPR sprout::complex<T>
sqrt_impl_2_1(sprout::complex<T> const& x, T const& t, T const& u) {
return x.real() > T() ? sprout::complex<T>(u, x.imag() / t)
: sprout::complex<T>(sprout::abs(x.imag()) / t, x.imag() < T() ? -u : u)
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt_impl_2(sprout::complex<T> const& x, T const& t) {
inline SPROUT_CONSTEXPR sprout::complex<T>
sqrt_impl_2(sprout::complex<T> const& x, T const& t) {
return sprout::detail::sqrt_impl_2_1(x, t, t / 2);
}
} // namespace detail
//
// tan
// tanh
//
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> sqrt(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
sqrt(sprout::complex<T> const& x) {
return x.real() == T() ? sprout::detail::sqrt_impl_1(x, sprout::sqrt(abs(x.imag()) / 2))
: sprout::detail::sqrt_impl_2(x, sprout::sqrt(2 * (sprout::abs(x) + sprout::abs(x.real()))))
;
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> tan(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
tan(sprout::complex<T> const& x) {
return sprout::sin(x) / sprout::cos(x);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> tanh(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
tanh(sprout::complex<T> const& x) {
return sprout::sinh(x) / sprout::cosh(x);
}
} // namespace sprout

View file

@ -11,36 +11,44 @@
namespace sprout {
template<typename T>
SPROUT_CONSTEXPR T norm(sprout::complex<T> const& x);
SPROUT_CONSTEXPR T
norm(sprout::complex<T> const& x);
// 26.4.7, values:
template<typename T>
inline SPROUT_CONSTEXPR T real(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR T
real(sprout::complex<T> const& x) {
return x.real();
}
template<typename T>
inline SPROUT_CONSTEXPR T imag(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR T
imag(sprout::complex<T> const& x) {
return x.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR T abs(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR T
abs(sprout::complex<T> const& x) {
return sprout::sqrt(sprout::norm(x));
}
template<typename T>
inline SPROUT_CONSTEXPR T arg(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR T
arg(sprout::complex<T> const& x) {
return sprout::atan2(x.imag(), x.real());
}
template<typename T>
inline SPROUT_CONSTEXPR T norm(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR T
norm(sprout::complex<T> const& x) {
return x.real() * x.real() + x.imag() * x.imag();
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> conj(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
conj(sprout::complex<T> const& x) {
return sprout::complex<T>(x.real(), -x.imag());
}
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> proj_impl(sprout::complex<T> const& x, T const& den) {
inline SPROUT_CONSTEXPR sprout::complex<T>
proj_impl(sprout::complex<T> const& x, T const& den) {
return sprout::complex<T>(
T(2) * x.real() / den,
T(2) * x.imag() / den
@ -48,14 +56,16 @@ namespace sprout {
}
} // detail
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> proj(sprout::complex<T> const& x) {
inline SPROUT_CONSTEXPR sprout::complex<T>
proj(sprout::complex<T> const& x) {
return sprout::detail::proj_impl(
x,
sprout::norm(x) + T(1)
);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::complex<T> polar(T const& rho, T const& theta = 0) {
inline SPROUT_CONSTEXPR sprout::complex<T>
polar(T const& rho, T const& theta = 0) {
return sprout::complex<T>(rho * sprout::cos(theta), rho * sprout::sin(theta));
}
} // namespace sprout

View file

@ -3,6 +3,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/swap.hpp>
#include <sprout/detail/call_traits.hpp>
namespace sprout {
@ -37,8 +38,7 @@ namespace sprout {
template<typename T1, typename T2, int Version>
class compressed_pair_impl;
template<typename T1, typename T2>
class compressed_pair_impl<T1, T2, 0>
{
class compressed_pair_impl<T1, T2, 0> {
public:
typedef T1 first_type;
typedef T2 second_type;
@ -75,10 +75,14 @@ namespace sprout {
SPROUT_CONSTEXPR second_const_reference second() const {
return second_;
}
void swap(compressed_pair_impl& other) {
using std::swap;
swap(first_, other.first_);
swap(second_, other.second_);
void swap(compressed_pair_impl& other)
SPROUT_NOEXCEPT_EXPR(
SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_))
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(second_, other.second_))
)
{
sprout::swap(first_, other.first_);
sprout::swap(second_, other.second_);
}
};
template<typename T1, typename T2>
@ -120,9 +124,10 @@ namespace sprout {
SPROUT_CONSTEXPR second_const_reference second() const {
return second_;
}
void swap(compressed_pair_impl& other) {
using std::swap;
swap(second_, other.second_);
void swap(compressed_pair_impl& other)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(second_, other.second_)))
{
sprout::swap(second_, other.second_);
}
};
template<typename T1, typename T2>
@ -164,9 +169,10 @@ namespace sprout {
SPROUT_CONSTEXPR second_const_reference second() const {
return *this;
}
void swap(compressed_pair_impl& other) {
using std::swap;
swap(first_, other.first_);
void swap(compressed_pair_impl& other)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_)))
{
sprout::swap(first_, other.first_);
}
};
template<typename T1, typename T2>
@ -285,10 +291,14 @@ namespace sprout {
SPROUT_CONSTEXPR second_const_reference second() const {
return second_;
}
void swap(compressed_pair_impl& other) {
using std::swap;
swap(first_, other.first_);
swap(second_, other.second_);
void swap(compressed_pair_impl& other)
SPROUT_NOEXCEPT_EXPR(
SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_))
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(second_, other.second_))
)
{
sprout::swap(first_, other.first_);
sprout::swap(second_, other.second_);
}
};
} // namespace detail
@ -299,27 +309,21 @@ namespace sprout {
template<typename T1, typename T2>
class compressed_pair
: private sprout::detail::compressed_pair_impl<
T1,
T2,
T1, T2,
sprout::detail::compressed_pair_switch<
T1,
T2,
T1, T2,
std::is_same<typename std::remove_cv<T1>::type, typename std::remove_cv<T2>::type>::value,
std::is_empty<T1>::value,
std::is_empty<T2>::value
std::is_empty<T1>::value, std::is_empty<T2>::value
>::value
>
{
private:
typedef sprout::detail::compressed_pair_impl<
T1,
T2,
T1, T2,
sprout::detail::compressed_pair_switch<
T1,
T2,
T1, T2,
std::is_same<typename std::remove_cv<T1>::type, typename std::remove_cv<T2>::type>::value,
std::is_empty<T1>::value,
std::is_empty<T2>::value
std::is_empty<T1>::value, std::is_empty<T2>::value
>::value
> base_type;
public:
@ -363,27 +367,21 @@ namespace sprout {
template<typename T>
class compressed_pair<T, T>
: private sprout::detail::compressed_pair_impl<
T,
T,
T, T,
sprout::detail::compressed_pair_switch<
T,
T,
T, T,
std::is_same<typename std::remove_cv<T>::type, typename std::remove_cv<T>::type>::value,
std::is_empty<T>::value,
std::is_empty<T>::value
std::is_empty<T>::value, std::is_empty<T>::value
>::value
>
{
private:
typedef sprout::detail::compressed_pair_impl<
T,
T,
T, T,
sprout::detail::compressed_pair_switch<
T,
T,
T, T,
std::is_same<typename std::remove_cv<T>::type, typename std::remove_cv<T>::type>::value,
std::is_empty<T>::value,
std::is_empty<T>::value
std::is_empty<T>::value, std::is_empty<T>::value
>::value
> base_type;
public:
@ -421,8 +419,14 @@ namespace sprout {
base_type::swap(other);
}
};
//
// swap
//
template<typename T1, typename T2>
inline void swap(sprout::compressed_pair<T1, T2>& lhs, sprout::compressed_pair<T1, T2>& rhs) {
inline void
swap(sprout::compressed_pair<T1, T2>& lhs, sprout::compressed_pair<T1, T2>& rhs)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
{
lhs.swap(rhs);
}
} // namespace sprout

View file

@ -27,20 +27,18 @@ namespace sprout {
typedef Container copied_type;
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& 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) {
static SPROUT_CONSTEXPR copied_type
make(Args&&... args) {
return sprout::detail::default_make_container<Container>(sprout::forward<Args>(args)...);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type remake(
Cont&& cont,
typename sprout::container_traits<Container>::difference_type size,
Args&&... args
)
{
static SPROUT_CONSTEXPR copied_type
remake(Cont&& cont, typename sprout::container_traits<Container>::difference_type size, Args&&... args) {
return make(sprout::forward<Args>(args)...);
}
};

View file

@ -8,57 +8,13 @@
#include <sprout/config.hpp>
#include <sprout/type_traits/has_xxx.hpp>
#include <sprout/type_traits/inherit_if_xxx.hpp>
#include <sprout/container/detail/array_like.hpp>
namespace sprout {
template<typename Container>
struct container_traits;
namespace detail {
//
// is_array_like
//
template<typename Container>
struct is_array_like
: public std::false_type
{};
template<template<typename, std::size_t> class Array, typename T, std::size_t N>
struct is_array_like<Array<T, N> >
: public std::true_type
{};
template<typename Container>
struct is_array_like<Container const>
: public sprout::detail::is_array_like<Container>
{};
template<typename Container>
struct is_array_like<Container volatile>
: public sprout::detail::is_array_like<Container>
{};
template<typename Container>
struct is_array_like<Container const volatile>
: public sprout::detail::is_array_like<Container>
{};
//
// array_like_static_size
//
template<typename Container>
struct array_like_static_size {};
template<template<typename, std::size_t> class Array, typename T, std::size_t N>
struct array_like_static_size<Array<T, N> >
: public std::integral_constant<std::size_t, N>
{};
template<typename Container>
struct array_like_static_size<Container const>
: public sprout::detail::array_like_static_size<Container>
{};
template<typename Container>
struct array_like_static_size<Container volatile>
: public sprout::detail::array_like_static_size<Container>
{};
template<typename Container>
struct array_like_static_size<Container const volatile>
: public sprout::detail::array_like_static_size<Container>
{};
//
// has_value_type
// has_iterator
@ -438,7 +394,8 @@ namespace sprout {
template<typename Container>
struct container_nosy_fixed_size_impl<Container, true> {
public:
static SPROUT_CONSTEXPR decltype(sprout::detail::container_nosy_static_size<Container>::static_size) fixed_size() {
static SPROUT_CONSTEXPR decltype(sprout::detail::container_nosy_static_size<Container>::static_size)
fixed_size() {
return sprout::detail::container_nosy_static_size<Container>::static_size;
}
};
@ -482,7 +439,8 @@ namespace sprout {
public:
SPROUT_STATIC_CONSTEXPR size_type static_size = N ;
public:
static SPROUT_CONSTEXPR size_type fixed_size() {
static SPROUT_CONSTEXPR size_type
fixed_size() {
return static_size;
}
};

View file

@ -5,6 +5,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/container_traits.hpp>
#include <sprout/container/detail/array_like.hpp>
namespace sprout {
//
@ -14,31 +15,6 @@ namespace sprout {
struct container_transform_traits;
namespace detail {
template<typename Container>
struct is_like_array_class
: public std::false_type
{};
template<
template<typename, std::size_t> class Array,
typename T,
std::size_t N
>
struct is_like_array_class<Array<T, N> >
: public std::true_type
{};
template<typename Container>
struct is_like_array_class<Container const>
: public sprout::detail::is_like_array_class<Container>
{};
template<typename Container>
struct is_like_array_class<Container volatile>
: public sprout::detail::is_like_array_class<Container>
{};
template<typename Container>
struct is_like_array_class<Container const volatile>
: public sprout::detail::is_like_array_class<Container>
{};
template<typename Container, typename sprout::container_traits<Container>::size_type Size>
struct default_array_rebind_size;
template<
@ -57,7 +33,7 @@ namespace sprout {
template<typename Container>
struct inherit_default_rebind_size<
Container,
typename std::enable_if<sprout::detail::is_like_array_class<Container>::value>::type
typename std::enable_if<sprout::detail::is_array_like<Container>::value>::type
> {
public:
template<typename sprout::container_traits<Container>::size_type Size>

View file

@ -13,7 +13,8 @@ namespace sprout {
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<
typename std::remove_reference<Container>::type
>::copied_type deep_copy(Container&& cont) {
>::copied_type
deep_copy(Container&& cont) {
typedef typename std::remove_reference<Container>::type container_type;
return sprout::container_construct_traits<container_type>::deep_copy(sprout::forward<Container>(cont));
}

View file

@ -0,0 +1,52 @@
#ifndef SPROUT_CONTAINER_DETAIL_ARRAY_LIKE_HPP
#define SPROUT_CONTAINER_DETAIL_ARRAY_LIKE_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace detail {
template<typename Container>
struct is_array_like
: public std::false_type
{};
template<template<typename, std::size_t> class Array, typename T, std::size_t N>
struct is_array_like<Array<T, N> >
: public std::true_type
{};
template<typename Container>
struct is_array_like<Container const>
: public sprout::detail::is_array_like<Container>
{};
template<typename Container>
struct is_array_like<Container volatile>
: public sprout::detail::is_array_like<Container>
{};
template<typename Container>
struct is_array_like<Container const volatile>
: public sprout::detail::is_array_like<Container>
{};
template<typename Container>
struct array_like_static_size {};
template<template<typename, std::size_t> class Array, typename T, std::size_t N>
struct array_like_static_size<Array<T, N> >
: public std::integral_constant<std::size_t, N>
{};
template<typename Container>
struct array_like_static_size<Container const>
: public sprout::detail::array_like_static_size<Container>
{};
template<typename Container>
struct array_like_static_size<Container volatile>
: public sprout::detail::array_like_static_size<Container>
{};
template<typename Container>
struct array_like_static_size<Container const volatile>
: public sprout::detail::array_like_static_size<Container>
{};
} // namespace detail
} // namespace sprout
#endif // #ifndef SPROUT_CONTAINER_DETAIL_ARRAY_LIKE_HPP

View file

@ -9,7 +9,8 @@ namespace sprout {
// fixed_size
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::size_type fixed_size() {
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::size_type
fixed_size() {
return sprout::container_traits<Container>::fixed_size();
}
} // namespace sprout

View file

@ -12,7 +12,8 @@ namespace sprout {
// get_internal
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::containers::internal<Container>::type get_internal(Container&& cont) {
inline SPROUT_CONSTEXPR typename sprout::containers::internal<Container>::type
get_internal(Container&& cont) {
typedef typename std::remove_reference<Container>::type container_type;
return sprout::sub_container_traits<container_type>::get_internal(sprout::forward<Container>(cont));
}

View file

@ -18,7 +18,8 @@ namespace sprout {
typename std::remove_reference<
typename sprout::containers::internal<Container&>::type
>::type
>::iterator internal_begin(Container& cont) {
>::iterator
internal_begin(Container& cont) {
return sprout::begin(sprout::get_internal(cont));
}
template<typename Container>
@ -26,7 +27,8 @@ namespace sprout {
typename std::remove_reference<
typename sprout::containers::internal<Container const&>::type
>::type
>::const_iterator internal_begin(Container const& cont) {
>::const_iterator
internal_begin(Container const& cont) {
return sprout::begin(sprout::get_internal(cont));
}
@ -38,7 +40,8 @@ namespace sprout {
typename std::remove_reference<
typename sprout::containers::internal<Container const&>::type
>::type
>::const_iterator internal_cbegin(Container const& cont) {
>::const_iterator
internal_cbegin(Container const& cont) {
return sprout::begin(sprout::get_internal(cont));
}
} // namespace sprout

View file

@ -19,7 +19,8 @@ namespace sprout {
typename std::remove_reference<
typename sprout::containers::internal<Container>::type
>::type
>::copied_type internal_deep_copy(Container&& cont) {
>::copied_type
internal_deep_copy(Container&& cont) {
return sprout::deep_copy(
sprout::get_internal(sprout::forward<Container>(cont))
);

View file

@ -18,7 +18,8 @@ namespace sprout {
typename std::remove_reference<
typename sprout::containers::internal<Container&>::type
>::type
>::iterator internal_end(Container& cont) {
>::iterator
internal_end(Container& cont) {
return sprout::end(sprout::get_internal(cont));
}
template<typename Container>
@ -26,7 +27,8 @@ namespace sprout {
typename std::remove_reference<
typename sprout::containers::internal<Container const&>::type
>::type
>::const_iterator internal_end(Container const& cont) {
>::const_iterator
internal_end(Container const& cont) {
return sprout::end(sprout::get_internal(cont));
}
@ -38,7 +40,8 @@ namespace sprout {
typename std::remove_reference<
typename sprout::containers::internal<Container const&>::type
>::type
>::const_iterator internal_cend(Container const& cont) {
>::const_iterator
internal_cend(Container const& cont) {
return sprout::end(sprout::get_internal(cont));
}
} // namespace sprout

View file

@ -10,7 +10,8 @@ namespace sprout {
// make
//
template<typename Container, typename... Args>
inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<Container>::copied_type make(Args&&... args) {
inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<Container>::copied_type
make(Args&&... args) {
return sprout::container_construct_traits<Container>::make(sprout::forward<Args>(args)...);
}
} // namespace sprout

View file

@ -12,12 +12,8 @@ namespace sprout {
// remake
//
template<typename Container, typename Cont, typename... Args>
inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<Container>::copied_type remake(
Cont&& cont,
typename sprout::container_traits<Container>::difference_type size,
Args&&... args
)
{
inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<Container>::copied_type
remake(Cont&& cont, typename sprout::container_traits<Container>::difference_type size, Args&&... args) {
return sprout::container_construct_traits<Container>::remake(
sprout::forward<Cont>(cont),
size,

View file

@ -9,23 +9,28 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.20.6.1 abs<62>Clabs<62>CyÑ llabs ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int abs(int j) {
inline SPROUT_CONSTEXPR int
abs(int j) {
return j < 0 ? -j : j;
}
inline SPROUT_CONSTEXPR long labs(long j) {
inline SPROUT_CONSTEXPR long
labs(long j) {
return j < 0 ? -j : j;
}
inline SPROUT_CONSTEXPR long long llabs(long long j) {
inline SPROUT_CONSTEXPR long long
llabs(long long j) {
return j < 0 ? -j : j;
}
inline SPROUT_CONSTEXPR long abs(long j) {
inline SPROUT_CONSTEXPR long
abs(long j) {
return sprout::labs(j);
}
inline SPROUT_CONSTEXPR long long abs(long long j) {
inline SPROUT_CONSTEXPR long long
abs(long long j) {
return sprout::llabs(j);
}
@ -36,7 +41,8 @@ namespace sprout {
std::is_integral<IntType>::value && std::is_signed<IntType>::value
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR IntType abs(IntType j) {
inline SPROUT_CONSTEXPR IntType
abs(IntType j) {
return j < 0 ? -j : j;
}
template<
@ -45,7 +51,8 @@ namespace sprout {
std::is_integral<IntType>::value && std::is_unsigned<IntType>::value
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR IntType abs(IntType j) {
inline SPROUT_CONSTEXPR IntType
abs(IntType j) {
return j;
}
} // anonymous-namespace

View file

@ -14,7 +14,8 @@ namespace sprout {
// Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/
template<typename IntType, typename CStrIterator>
inline SPROUT_CONSTEXPR IntType ascii_to_int_impl(CStrIterator str, IntType val, bool negative) {
inline SPROUT_CONSTEXPR IntType
ascii_to_int_impl(CStrIterator str, IntType val, bool negative) {
return !sprout::ascii::isdigit(*str)
? negative ? -val : val
: val > (std::numeric_limits<IntType>::max() - (*str - static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')) - (negative ? 1 : 0)) / 10
@ -27,7 +28,8 @@ namespace sprout {
;
}
template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_unsigned<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) {
inline SPROUT_CONSTEXPR IntType
ascii_to_int(CStrIterator 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>('+')
@ -36,7 +38,8 @@ namespace sprout {
;
}
template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_signed<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) {
inline SPROUT_CONSTEXPR IntType
ascii_to_int(CStrIterator 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>('-')
@ -52,7 +55,8 @@ namespace sprout {
// ascii_to_int
//
template<typename IntType, typename Char, typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType ascii_to_int(Char const* str) {
inline SPROUT_CONSTEXPR IntType
ascii_to_int(Char const* str) {
return sprout::detail::ascii_to_int<IntType>(str);
}
} // namespace sprout

View file

@ -9,7 +9,8 @@ namespace sprout {
// atof
//
template<typename Char>
inline SPROUT_CONSTEXPR double atof(Char const* str){
inline SPROUT_CONSTEXPR double
atof(Char const* str) {
return sprout::str_to_float<double>(str);
}
} // namespace sprout

View file

@ -8,11 +8,13 @@ namespace sprout {
//
// atoi
//
inline SPROUT_CONSTEXPR int atoi(char const* str) {
inline SPROUT_CONSTEXPR int
atoi(char const* str) {
return sprout::ascii_to_int<int>(str);
}
template<typename Char>
inline SPROUT_CONSTEXPR int atoi(Char const* str) {
inline SPROUT_CONSTEXPR int
atoi(Char const* str) {
return sprout::ascii_to_int<int>(str);
}
} // namespace sprout

View file

@ -8,11 +8,13 @@ namespace sprout {
//
// atol
//
inline SPROUT_CONSTEXPR long atol(char const* str) {
inline SPROUT_CONSTEXPR long
atol(char const* str) {
return sprout::ascii_to_int<long>(str);
}
template<typename Char>
inline SPROUT_CONSTEXPR long atol(Char const* str) {
inline SPROUT_CONSTEXPR long
atol(Char const* str) {
return sprout::ascii_to_int<long>(str);
}
} // namespace sprout

View file

@ -8,11 +8,13 @@ namespace sprout {
//
// atoll
//
inline SPROUT_CONSTEXPR long long atoll(char const* str) {
inline SPROUT_CONSTEXPR long long
atoll(char const* str) {
return sprout::ascii_to_int<long long>(str);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long atoll(Char const* str) {
inline SPROUT_CONSTEXPR long long
atoll(Char const* str) {
return sprout::ascii_to_int<long long>(str);
}
} // namespace sprout

View file

@ -34,7 +34,8 @@ namespace sprout {
sprout::detail::div_t_traits<T>::offsetof_quot == 0
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits<T>::type div_impl(T const& numer, T const& denom) {
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits<T>::type
div_impl(T const& numer, T const& denom) {
return {numer / denom, numer % denom};
}
@ -44,29 +45,35 @@ namespace sprout {
sprout::detail::div_t_traits<T>::offsetof_rem == 0
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits<T>::type div_impl(T const &numer, T const& denom) {
inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits<T>::type
div_impl(T const &numer, T const& denom) {
return {numer % denom, numer / denom};
}
} // namespace detail
// 7.20.6.2 div<69>Cldiv<69>CyÑ lldiv ŠÖ<C5A0>
inline SPROUT_CONSTEXPR std::div_t div(int numer, int denom) {
inline SPROUT_CONSTEXPR std::div_t
div(int numer, int denom) {
return sprout::detail::div_impl(numer, denom);
}
inline SPROUT_CONSTEXPR std::ldiv_t ldiv(long numer, long denom) {
inline SPROUT_CONSTEXPR std::ldiv_t
ldiv(long numer, long denom) {
return sprout::detail::div_impl(numer, denom);
}
inline SPROUT_CONSTEXPR std::lldiv_t lldiv(long long numer, long long denom) {
inline SPROUT_CONSTEXPR std::lldiv_t
lldiv(long long numer, long long denom) {
return sprout::detail::div_impl(numer, denom);
}
inline SPROUT_CONSTEXPR std::ldiv_t div(long numer, long denom) {
inline SPROUT_CONSTEXPR std::ldiv_t
div(long numer, long denom) {
return sprout::ldiv(numer, denom);
}
inline SPROUT_CONSTEXPR std::lldiv_t div(long long numer, long long denom) {
inline SPROUT_CONSTEXPR std::lldiv_t
div(long long numer, long long denom) {
return sprout::lldiv(numer, denom);
}
} // namespace sprout

View file

@ -13,7 +13,8 @@
namespace sprout {
namespace detail {
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl_scale(
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_scale(
CStrIterator str,
bool negative,
FloatType number = FloatType(),
@ -38,7 +39,8 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl_exponent_2(
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_exponent_2(
CStrIterator str,
bool negative,
FloatType number = FloatType(),
@ -63,7 +65,8 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl_exponent_1(
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_exponent_1(
CStrIterator str,
bool negative,
FloatType number = FloatType(),
@ -95,7 +98,8 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl_exponent(
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_exponent(
CStrIterator str,
bool negative,
FloatType number = FloatType(),
@ -134,7 +138,8 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl_decimal_1(
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_decimal_1(
CStrIterator str,
bool negative,
FloatType number = FloatType(),
@ -155,7 +160,8 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl_decimal(
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl_decimal(
CStrIterator str,
bool negative,
FloatType number = FloatType(),
@ -185,7 +191,8 @@ namespace sprout {
}
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl(
inline SPROUT_CONSTEXPR FloatType
str_to_float_impl(
CStrIterator str,
bool negative,
FloatType number = FloatType(),
@ -214,7 +221,8 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float(CStrIterator str) {
inline SPROUT_CONSTEXPR FloatType
str_to_float(CStrIterator 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>('-')
@ -225,7 +233,8 @@ namespace sprout {
;
}
template<typename FloatType, typename CStrIterator, typename CharPtr>
inline SPROUT_CONSTEXPR FloatType str_to_float(CStrIterator str, CharPtr* endptr) {
inline SPROUT_CONSTEXPR FloatType
str_to_float(CStrIterator str, CharPtr* endptr) {
return !endptr ? sprout::detail::str_to_float<FloatType>(str)
: std::is_same<typename std::remove_cv<FloatType>::type, float>::value ? std::strtof(&*str, endptr)
: std::is_same<typename std::remove_cv<FloatType>::type, double>::value ? std::strtod(&*str, endptr)
@ -238,15 +247,18 @@ namespace sprout {
// str_to_float
//
template<typename FloatType, typename Char, typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR FloatType str_to_float(Char const* str, Char** endptr) {
inline SPROUT_CONSTEXPR FloatType
str_to_float(Char const* str, Char** endptr) {
return sprout::detail::str_to_float<FloatType>(str, endptr);
}
template<typename FloatType, typename Char, typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR FloatType str_to_float(Char const* str, std::nullptr_t endptr) {
inline SPROUT_CONSTEXPR FloatType
str_to_float(Char const* str, std::nullptr_t endptr) {
return sprout::detail::str_to_float<FloatType>(str);
}
template<typename FloatType, typename Char, typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR FloatType str_to_float(Char const* str) {
inline SPROUT_CONSTEXPR FloatType
str_to_float(Char const* str) {
return sprout::detail::str_to_float<FloatType>(str);
}
} // namespace sprout

View file

@ -17,9 +17,9 @@ namespace sprout {
// Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/
template<typename IntType, typename CStrIterator>
inline SPROUT_CONSTEXPR IntType str_to_int_impl_1(CStrIterator str, int base, IntType val, IntType x, bool negative) {
return x == static_cast<IntType>(-1)
? (negative ? -val : val)
inline SPROUT_CONSTEXPR IntType
str_to_int_impl_1(CStrIterator str, int base, IntType val, IntType x, bool negative) {
return x == static_cast<IntType>(-1) ? (negative ? -val : val)
: val > (std::numeric_limits<IntType>::max() - x - (negative ? 1 : 0)) / base
? (negative ? std::numeric_limits<IntType>::min() : std::numeric_limits<IntType>::max())
: sprout::detail::str_to_int_impl_1<IntType>(
@ -32,7 +32,8 @@ namespace sprout {
;
}
template<typename IntType, typename CStrIterator>
inline SPROUT_CONSTEXPR IntType str_to_int_impl(CStrIterator str, int base, bool negative) {
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')
@ -60,7 +61,8 @@ namespace sprout {
;
}
template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_unsigned<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) {
inline SPROUT_CONSTEXPR IntType
str_to_int(CStrIterator 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>('+')
@ -69,7 +71,8 @@ namespace sprout {
;
}
template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_signed<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) {
inline SPROUT_CONSTEXPR IntType
str_to_int(CStrIterator 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>('-')
@ -80,7 +83,8 @@ namespace sprout {
;
}
template<typename IntType, typename CStrIterator, typename CharPtr>
inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, CharPtr* endptr, int base) {
inline SPROUT_CONSTEXPR IntType
str_to_int(CStrIterator str, CharPtr* endptr, int base) {
return !endptr ? sprout::detail::str_to_int<IntType>(str, base)
: std::is_signed<IntType>::value
? sizeof(IntType) <= sizeof(long) ? static_cast<IntType>(std::strtol(&*str, endptr, base))
@ -97,15 +101,18 @@ namespace sprout {
// str_to_int
//
template<typename IntType, typename Char, typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType str_to_int(Char const* str, Char** endptr, int base = 10) {
inline SPROUT_CONSTEXPR IntType
str_to_int(Char const* str, Char** endptr, int base = 10) {
return sprout::detail::str_to_int<IntType>(str, endptr, base);
}
template<typename IntType, typename Char, typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType str_to_int(Char const* str, std::nullptr_t endptr, int base = 10) {
inline SPROUT_CONSTEXPR IntType
str_to_int(Char const* str, std::nullptr_t endptr, int base = 10) {
return sprout::detail::str_to_int<IntType>(str, base);
}
template<typename IntType, typename Char, typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType str_to_int(Char const* str, int base = 10) {
inline SPROUT_CONSTEXPR IntType
str_to_int(Char const* str, int base = 10) {
return sprout::detail::str_to_int<IntType>(str, base);
}
} // namespace sprout

View file

@ -10,15 +10,18 @@ namespace sprout {
// strtod
//
template<typename Char>
inline SPROUT_CONSTEXPR double strtod(Char const* str, Char** endptr){
inline SPROUT_CONSTEXPR double
strtod(Char const* str, Char** endptr) {
return sprout::str_to_float<double>(str, endptr);
}
template<typename Char>
inline SPROUT_CONSTEXPR double strtod(Char const* str, std::nullptr_t endptr){
inline SPROUT_CONSTEXPR double
strtod(Char const* str, std::nullptr_t endptr) {
return sprout::str_to_float<double>(str);
}
template<typename Char>
inline SPROUT_CONSTEXPR double strtod(Char const* str){
inline SPROUT_CONSTEXPR double
strtod(Char const* str) {
return sprout::str_to_float<double>(str);
}
} // namespace sprout

View file

@ -10,15 +10,18 @@ namespace sprout {
// strtof
//
template<typename Char>
inline SPROUT_CONSTEXPR float strtof(Char const* str, Char** endptr){
inline SPROUT_CONSTEXPR float
strtof(Char const* str, Char** endptr) {
return sprout::str_to_float<float>(str, endptr);
}
template<typename Char>
inline SPROUT_CONSTEXPR float strtof(Char const* str, std::nullptr_t endptr){
inline SPROUT_CONSTEXPR float
strtof(Char const* str, std::nullptr_t endptr) {
return sprout::str_to_float<float>(str);
}
template<typename Char>
inline SPROUT_CONSTEXPR float strtof(Char const* str){
inline SPROUT_CONSTEXPR float
strtof(Char const* str) {
return sprout::str_to_float<float>(str);
}
} // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
//
// strtol
//
inline SPROUT_CONSTEXPR long strtol(char const* str, char** endptr, int base = 10){
inline SPROUT_CONSTEXPR long
strtol(char const* str, char** endptr, int base = 10) {
return sprout::str_to_int<long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long strtol(Char const* str, Char** endptr, int base = 10){
inline SPROUT_CONSTEXPR long
strtol(Char const* str, Char** endptr, int base = 10) {
return sprout::str_to_int<long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long strtol(Char const* str, std::nullptr_t endptr, int base = 10){
inline SPROUT_CONSTEXPR long
strtol(Char const* str, std::nullptr_t endptr, int base = 10) {
return sprout::str_to_int<long>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long strtol(Char const* str, int base = 10){
inline SPROUT_CONSTEXPR long
strtol(Char const* str, int base = 10) {
return sprout::str_to_int<long>(str, base);
}
} // namespace sprout

View file

@ -10,15 +10,18 @@ namespace sprout {
// strtold
//
template<typename Char>
inline SPROUT_CONSTEXPR long double strtold(Char const* str, Char** endptr){
inline SPROUT_CONSTEXPR long double
strtold(Char const* str, Char** endptr) {
return sprout::str_to_float<long double>(str, endptr);
}
template<typename Char>
inline SPROUT_CONSTEXPR long double strtold(Char const* str, std::nullptr_t endptr){
inline SPROUT_CONSTEXPR long double
strtold(Char const* str, std::nullptr_t endptr) {
return sprout::str_to_float<long double>(str);
}
template<typename Char>
inline SPROUT_CONSTEXPR long double strtold(Char const* str){
inline SPROUT_CONSTEXPR long double
strtold(Char const* str) {
return sprout::str_to_float<long double>(str);
}
} // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
//
// strtol
//
inline SPROUT_CONSTEXPR long long strtoll(char const* str, char** endptr, int base = 10){
inline SPROUT_CONSTEXPR long long
strtoll(char const* str, char** endptr, int base = 10) {
return sprout::str_to_int<long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long strtoll(Char const* str, Char** endptr, int base = 10){
inline SPROUT_CONSTEXPR long long
strtoll(Char const* str, Char** endptr, int base = 10) {
return sprout::str_to_int<long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long strtoll(Char const* str, std::nullptr_t endptr, int base = 10){
inline SPROUT_CONSTEXPR long long
strtoll(Char const* str, std::nullptr_t endptr, int base = 10) {
return sprout::str_to_int<long long>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long strtoll(Char const* str, int base = 10){
inline SPROUT_CONSTEXPR long long
strtoll(Char const* str, int base = 10) {
return sprout::str_to_int<long long>(str, base);
}
} // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
//
// strtoul
//
inline SPROUT_CONSTEXPR unsigned long strtoul(char const* str, char** endptr, int base = 10){
inline SPROUT_CONSTEXPR unsigned long
strtoul(char const* str, char** endptr, int base = 10) {
return sprout::str_to_int<unsigned long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, Char** endptr, int base = 10){
inline SPROUT_CONSTEXPR unsigned long
strtoul(Char const* str, Char** endptr, int base = 10) {
return sprout::str_to_int<unsigned long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, std::nullptr_t endptr, int base = 10){
inline SPROUT_CONSTEXPR unsigned long
strtoul(Char const* str, std::nullptr_t endptr, int base = 10) {
return sprout::str_to_int<unsigned long>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, int base = 10){
inline SPROUT_CONSTEXPR unsigned long
strtoul(Char const* str, int base = 10) {
return sprout::str_to_int<unsigned long>(str, base);
}
} // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
//
// strtoul
//
inline SPROUT_CONSTEXPR unsigned long long strtoull(char const* str, char** endptr, int base = 10){
inline SPROUT_CONSTEXPR unsigned long long
strtoull(char const* str, char** endptr, int base = 10) {
return sprout::str_to_int<unsigned long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, Char** endptr, int base = 10){
inline SPROUT_CONSTEXPR unsigned long long
strtoull(Char const* str, Char** endptr, int base = 10) {
return sprout::str_to_int<unsigned long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, std::nullptr_t endptr, int base = 10){
inline SPROUT_CONSTEXPR unsigned long long
strtoull(Char const* str, std::nullptr_t endptr, int base = 10) {
return sprout::str_to_int<unsigned long long>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, int base = 10){
inline SPROUT_CONSTEXPR unsigned long long
strtoull(Char const* str, int base = 10) {
return sprout::str_to_int<unsigned long long>(str, base);
}
} // namespace sprout

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR void const* memchr_impl(unsigned char const* s, unsigned char c, std::size_t n) {
inline SPROUT_CONSTEXPR void const*
memchr_impl(unsigned char const* s, unsigned char c, std::size_t n) {
return !n ? 0
: *s == c ? s
: sprout::detail::memchr_impl(s + 1, c, n - 1)
@ -17,11 +18,13 @@ namespace sprout {
} // namespace detail
// 7.21.5.1 memchr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR void const* memchr(void const* s, int c, size_t n) {
inline SPROUT_CONSTEXPR void const*
memchr(void const* s, int c, size_t n) {
return sprout::detail::memchr_impl(static_cast<unsigned char const*>(s), static_cast<unsigned char>(c), n);
}
inline SPROUT_CONSTEXPR void* memchr(void* s, int c, size_t n) {
inline SPROUT_CONSTEXPR void*
memchr(void* s, int c, size_t n) {
return const_cast<void*>(
sprout::detail::memchr_impl(static_cast<unsigned char*>(s), static_cast<unsigned char>(c), n)
);

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR int memcmp_impl(unsigned char const* s1, unsigned char const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR int
memcmp_impl(unsigned char const* s1, unsigned char const* s2, std::size_t n) {
return !n ? 0
: *s1 == *s2 ? sprout::detail::memcmp_impl(s1 + 1, s2 + 1, n - 1)
: *s1 - *s2
@ -17,7 +18,8 @@ namespace sprout {
} // namespace detail
// 7.21.4.1 memcmp ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int memcmp(void const* s1, void const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR int
memcmp(void const* s1, void const* s2, std::size_t n) {
return sprout::detail::memcmp_impl(
static_cast<unsigned char const*>(s1),
static_cast<unsigned char const*>(s2),

View file

@ -8,14 +8,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.2 strchr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strchr(char const* s, int c) {
inline SPROUT_CONSTEXPR char const*
strchr(char const* s, int c) {
return *s == static_cast<char>(c) ? s
: !*s ? nullptr
: sprout::strchr(s + 1, c)
;
}
inline SPROUT_CONSTEXPR char* strchr(char* s, int c) {
inline SPROUT_CONSTEXPR char*
strchr(char* s, int c) {
return const_cast<char*>(sprout::strchr(const_cast<char const*>(s), c));
}
} // namespace sprout

View file

@ -7,7 +7,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.2 strcmp ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int strcmp(char const* s1, char const* s2) {
inline SPROUT_CONSTEXPR int
strcmp(char const* s1, char const* s2) {
return !*s1 && !*s2 ? 0
: !*s1 ? -1
: !*s2 ? 1

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.3 strcoll ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int strcoll(char const* s1, char const* s2) {
inline SPROUT_CONSTEXPR int
strcoll(char const* s1, char const* s2) {
return sprout::strcmp(s1, s2);
}
} // namespace sprout

View file

@ -9,7 +9,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t strcspn_impl(char const* s1, char const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR std::size_t
strcspn_impl(char const* s1, char const* s2, std::size_t n) {
return !*s1 || sprout::strchr(s2, *s1) ? n
: sprout::detail::strcspn_impl(s1 + 1, s2, n + 1)
;
@ -17,7 +18,8 @@ namespace sprout {
} // amespace detail
// 7.21.5.3 strcspn ŠÖ<C5A0>
inline SPROUT_CONSTEXPR std::size_t strcspn(char const* s1, char const* s2) {
inline SPROUT_CONSTEXPR std::size_t
strcspn(char const* s1, char const* s2) {
return sprout::detail::strcspn_impl(s1, s2, 0);
}
} // namespace sprout

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t strlen_impl(char const* s, std::size_t n) {
inline SPROUT_CONSTEXPR std::size_t
strlen_impl(char const* s, std::size_t n) {
return !*s ? n :
sprout::detail::strlen_impl(s + 1, n + 1)
;
@ -16,7 +17,8 @@ namespace sprout {
} // namespace detail
// 7.21.6.3 strlen ŠÖ<C5A0>
inline SPROUT_CONSTEXPR std::size_t strlen(char const* s) {
inline SPROUT_CONSTEXPR std::size_t
strlen(char const* s) {
return sprout::detail::strlen_impl(s, 0);
}
} // namespace sprout

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.4 strncmp ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int strncmp(char const* s1, char const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR int
strncmp(char const* s1, char const* s2, std::size_t n) {
return !n || (!*s1 && !*s2) ? 0
: !*s1 ? -1
: !*s2 ? 1

View file

@ -9,14 +9,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.4 strpbrk ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strpbrk(char const* s1, char const* s2) {
inline SPROUT_CONSTEXPR char const*
strpbrk(char const* s1, char const* s2) {
return !*s1 ? nullptr
: sprout::strchr(s2, *s1) ? s1
: sprout::strpbrk(s1 + 1, s2)
;
}
inline SPROUT_CONSTEXPR char* strpbrk(char* s1, char const* s2) {
inline SPROUT_CONSTEXPR char*
strpbrk(char* s1, char const* s2) {
return const_cast<char*>(sprout::strpbrk(const_cast<char const*>(s1), s2));
}
} // namespace sprout

View file

@ -8,14 +8,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.5 strrchr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strrchr(char const* s, int c) {
inline SPROUT_CONSTEXPR char const*
strrchr(char const* s, int c) {
return *s == static_cast<char>(c) && (!*s || !sprout::strrchr(s + 1, c))? s
: !*s ? nullptr
: sprout::strrchr(s + 1, c)
;
}
inline SPROUT_CONSTEXPR char* strrchr(char* s, int c) {
inline SPROUT_CONSTEXPR char*
strrchr(char* s, int c) {
return const_cast<char*>(sprout::strrchr(const_cast<char const*>(s), c));
}
} // namespace sprout

View file

@ -9,7 +9,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t strspn_impl(char const* s1, char const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR std::size_t
strspn_impl(char const* s1, char const* s2, std::size_t n) {
return !*s1 || !sprout::strchr(s2, *s1) ? n
: sprout::detail::strspn_impl(s1 + 1, s2, n + 1)
;
@ -17,7 +18,8 @@ namespace sprout {
} // namespace detail
// 7.21.5.6 strspn ŠÖ<C5A0>
inline SPROUT_CONSTEXPR std::size_t strspn(char const* s1, char const* s2) {
inline SPROUT_CONSTEXPR std::size_t
strspn(char const* s1, char const* s2) {
return sprout::detail::strspn_impl(s1, s2, 0);
}
} // namespace sprout

View file

@ -7,7 +7,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.7 strstr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strstr(char const* s1, char const* s2) {
inline SPROUT_CONSTEXPR char const*
strstr(char const* s1, char const* s2) {
return !*s2 ? s1
: !*s1 ? nullptr
: *s1 == *s2 && sprout::strstr(s1 + 1, s2 + 1) ? s1
@ -15,7 +16,8 @@ namespace sprout {
;
}
inline SPROUT_CONSTEXPR char* strstr(char* s1, char const* s2) {
inline SPROUT_CONSTEXPR char*
strstr(char* s1, char const* s2) {
return const_cast<char*>(sprout::strstr(const_cast<char const*>(s1), s2));
}
} // namespace sprout

View file

@ -180,46 +180,60 @@ namespace sprout {
} // namespace detail
#define SPROUT_CTYPE_ASCII_DECL(CHAR_TYPE, PREFIX) \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alnum))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alnum))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & (sprout::ascii::detail::alpha | sprout::ascii::detail::digit); \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alpha))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alpha))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::alpha; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, blank))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, blank))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::blank; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, cntrl))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, cntrl))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::cntrl; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, digit))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, digit))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::digit; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, graph))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, graph))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::graph; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::lower; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, print))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, print))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::print; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, punct))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, punct))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::punct; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, space))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, space))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::space; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper; \
} \
inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, xdigit))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR bool \
SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, xdigit))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::xdigit; \
} \
inline SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR CHAR_TYPE \
SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::lower ? c + (0x61 - 0x41) : c; \
} \
inline SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \
inline SPROUT_CONSTEXPR CHAR_TYPE \
SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \
return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper ? c - (0x61 - 0x41) : c; \
}

View file

@ -7,14 +7,16 @@
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR wchar_t const* wcschr(wchar_t const* s, int c) {
inline SPROUT_CONSTEXPR wchar_t const*
wcschr(wchar_t const* s, int c) {
return *s == static_cast<wchar_t>(c) ? s
: !*s ? nullptr
: sprout::wcschr(s + 1, c)
;
}
inline SPROUT_CONSTEXPR wchar_t* wcschr(wchar_t* s, int c) {
inline SPROUT_CONSTEXPR wchar_t*
wcschr(wchar_t* s, int c) {
return const_cast<wchar_t*>(sprout::wcschr(const_cast<wchar_t const*>(s), c));
}
} // namespace sprout

View file

@ -6,7 +6,8 @@
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR int wcscmp(wchar_t const* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR int
wcscmp(wchar_t const* s1, wchar_t const* s2) {
return !*s1 && !*s2 ? 0
: !*s1 ? -1
: !*s2 ? 1

View file

@ -7,7 +7,8 @@
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR int wcscoll(wchar_t const* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR int
wcscoll(wchar_t const* s1, wchar_t const* s2) {
return sprout::wcscmp(s1, s2);
}
} // namespace sprout

View file

@ -9,14 +9,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t wcscspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR std::size_t
wcscspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
return !*s1 || sprout::wcschr(s2, *s1) ? n
: sprout::detail::wcscspn_impl(s1 + 1, s2, n + 1)
;
}
} // amespace detail
inline SPROUT_CONSTEXPR std::size_t wcscspn(wchar_t const* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR std::size_t
wcscspn(wchar_t const* s1, wchar_t const* s2) {
return sprout::detail::wcscspn_impl(s1, s2, 0);
}
} // namespace sprout

View file

@ -8,14 +8,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t wcslen_impl(wchar_t const* s, std::size_t n) {
inline SPROUT_CONSTEXPR std::size_t
wcslen_impl(wchar_t const* s, std::size_t n) {
return !*s ? n :
sprout::detail::wcslen_impl(s + 1, n + 1)
;
}
} // namespace detail
inline SPROUT_CONSTEXPR std::size_t wcslen(wchar_t const* s) {
inline SPROUT_CONSTEXPR std::size_t
wcslen(wchar_t const* s) {
return sprout::detail::wcslen_impl(s, 0);
}
} // namespace sprout

View file

@ -7,7 +7,8 @@
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR int wcsncmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR int
wcsncmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
return !n || (!*s1 && !*s2) ? 0
: !*s1 ? -1
: !*s2 ? 1

View file

@ -8,14 +8,16 @@
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR wchar_t const* wcspbrk(wchar_t const* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR wchar_t const*
wcspbrk(wchar_t const* s1, wchar_t const* s2) {
return !*s1 ? nullptr
: sprout::wcschr(s2, *s1) ? s1
: sprout::wcspbrk(s1 + 1, s2)
;
}
inline SPROUT_CONSTEXPR wchar_t* wcspbrk(wchar_t* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR wchar_t*
wcspbrk(wchar_t* s1, wchar_t const* s2) {
return const_cast<wchar_t*>(sprout::wcspbrk(const_cast<wchar_t const*>(s1), s2));
}
} // namespace sprout

View file

@ -7,14 +7,16 @@
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR wchar_t const* wcsrchr(wchar_t const* s, int c) {
inline SPROUT_CONSTEXPR wchar_t const*
wcsrchr(wchar_t const* s, int c) {
return *s == static_cast<wchar_t>(c) && (!*s || !sprout::wcsrchr(s + 1, c))? s
: !*s ? nullptr
: sprout::wcsrchr(s + 1, c)
;
}
inline SPROUT_CONSTEXPR wchar_t* wcsrchr(wchar_t* s, int c) {
inline SPROUT_CONSTEXPR wchar_t*
wcsrchr(wchar_t* s, int c) {
return const_cast<wchar_t*>(sprout::wcsrchr(const_cast<wchar_t const*>(s), c));
}
} // namespace sprout

View file

@ -9,14 +9,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t wcsspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR std::size_t
wcsspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
return !*s1 || !sprout::wcschr(s2, *s1) ? n
: sprout::detail::wcsspn_impl(s1 + 1, s2, n + 1)
;
}
} // namespace detail
inline SPROUT_CONSTEXPR std::size_t wcsspn(wchar_t const* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR std::size_t
wcsspn(wchar_t const* s1, wchar_t const* s2) {
return sprout::detail::wcsspn_impl(s1, s2, 0);
}
} // namespace sprout

View file

@ -6,7 +6,8 @@
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR wchar_t const* wcsstr(wchar_t const* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR wchar_t const*
wcsstr(wchar_t const* s1, wchar_t const* s2) {
return !*s2 ? s1
: !*s1 ? nullptr
: *s1 == *s2 && sprout::wcsstr(s1 + 1, s2 + 1) ? s1
@ -14,7 +15,8 @@ namespace sprout {
;
}
inline SPROUT_CONSTEXPR wchar_t* wcsstr(wchar_t* s1, wchar_t const* s2) {
inline SPROUT_CONSTEXPR wchar_t*
wcsstr(wchar_t* s1, wchar_t const* s2) {
return const_cast<wchar_t*>(sprout::wcsstr(const_cast<wchar_t const*>(s1), s2));
}
} // namespace sprout

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR wchar_t const* wmemchr_impl(wchar_t const* s, wchar_t c, std::size_t n) {
inline SPROUT_CONSTEXPR wchar_t const*
wmemchr_impl(wchar_t const* s, wchar_t c, std::size_t n) {
return !n ? 0
: *s == c ? s
: sprout::detail::wmemchr_impl(s + 1, c, n - 1)
@ -16,14 +17,14 @@ namespace sprout {
}
} // namespace detail
inline SPROUT_CONSTEXPR wchar_t const* wmemchr(wchar_t const* s, wchar_t c, size_t n) {
inline SPROUT_CONSTEXPR wchar_t const*
wmemchr(wchar_t const* s, wchar_t c, size_t n) {
return sprout::detail::wmemchr_impl(s, c, n);
}
inline SPROUT_CONSTEXPR wchar_t* wmemchr(wchar_t* s, wchar_t c, size_t n) {
return const_cast<wchar_t*>(
sprout::detail::wmemchr_impl(s, c, n)
);
inline SPROUT_CONSTEXPR wchar_t*
wmemchr(wchar_t* s, wchar_t c, size_t n) {
return const_cast<wchar_t*>(sprout::detail::wmemchr_impl(s, c, n));
}
} // namespace sprout

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR int wmemcmp_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
inline SPROUT_CONSTEXPR int
wmemcmp_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
return !n ? 0
: *s1 == *s2 ? sprout::detail::wmemcmp_impl(s1 + 1, s2 + 1, n - 1)
: *s1 - *s2
@ -16,12 +17,9 @@ namespace sprout {
}
} // namespace detail
inline SPROUT_CONSTEXPR int wmemcmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
return sprout::detail::wmemcmp_impl(
s1,
s2,
n
);
inline SPROUT_CONSTEXPR int
wmemcmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
return sprout::detail::wmemcmp_impl(s1, s2, n);
}
} // namespace sprout

View file

@ -34,7 +34,8 @@ namespace sprout {
// get
//
template<std::size_t I, typename T>
inline SPROUT_CONSTEXPR auto get(T&& t)
inline SPROUT_CONSTEXPR auto
get(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<I>(sprout::forward<T>(t))))
-> decltype(sprout::tuples::get<I>(sprout::forward<T>(t)))
{

View file

@ -29,13 +29,8 @@ namespace sprout {
position_type fixation_point_;
unit_type rotate_;
private:
SPROUT_CONSTEXPR position_type transform_1(
position_type const& c,
unit_type const& u,
unit_type const& v,
unit_type const& l
) const
{
SPROUT_CONSTEXPR position_type
transform_1(position_type const& c, unit_type const& u, unit_type const& v, unit_type const& l) const {
return sprout::darkroom::coords::add(
c,
position_type(
@ -45,12 +40,8 @@ namespace sprout {
)
);
}
SPROUT_CONSTEXPR position_type transform(
position_type const& c,
unit_type const& u,
unit_type const& v
) const
{
SPROUT_CONSTEXPR position_type
transform(position_type const& c, unit_type const& u, unit_type const& v) const {
return transform_1(
c,
u * sprout::cos(rotate_) - v * sprout::sin(rotate_),
@ -62,11 +53,10 @@ namespace sprout {
);
}
template<typename Unit2D>
SPROUT_CONSTEXPR position_type reference_width(
Unit2D const& x,
Unit2D const& y,
Unit2D const& width,
Unit2D const& height,
SPROUT_CONSTEXPR position_type
reference_width(
Unit2D const& x, Unit2D const& y,
Unit2D const& width, Unit2D const& height,
unit_type const& rate
) const
{
@ -80,11 +70,10 @@ namespace sprout {
);
}
template<typename Unit2D>
SPROUT_CONSTEXPR position_type reference_height(
Unit2D const& x,
Unit2D const& y,
Unit2D const& width,
Unit2D const& height,
SPROUT_CONSTEXPR position_type
reference_height(
Unit2D const& x, Unit2D const& y,
Unit2D const& width, Unit2D const& height,
unit_type const& rate
) const
{
@ -112,13 +101,8 @@ namespace sprout {
, rotate_(rotate)
{}
template<typename Unit2D>
SPROUT_CONSTEXPR ray_type operator()(
Unit2D const& x,
Unit2D const& y,
Unit2D const& width,
Unit2D const& height
) const
{
SPROUT_CONSTEXPR ray_type
operator()(Unit2D const& x, Unit2D const& y, Unit2D const& width, Unit2D const& height) const {
return ray_type(
position_,
sprout::darkroom::coords::normalize(

View file

@ -19,28 +19,32 @@ namespace sprout {
// a
//
template<typename T>
inline SPROUT_CONSTEXPR auto r(T&& t)
inline SPROUT_CONSTEXPR auto
r(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<0>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto g(T&& t)
inline SPROUT_CONSTEXPR auto
g(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<1>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto b(T&& t)
inline SPROUT_CONSTEXPR auto
b(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<2>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<2>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto a(T&& t)
inline SPROUT_CONSTEXPR auto
a(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<3>(sprout::forward<T>(t)))
{
@ -58,7 +62,8 @@ namespace sprout {
// mul
//
template<typename Color, typename Fac>
inline SPROUT_CONSTEXPR Color mul(Color const& lhs, Fac const& rhs) {
inline SPROUT_CONSTEXPR Color
mul(Color const& lhs, Fac const& rhs) {
return sprout::tuples::remake<Color>(
lhs,
sprout::darkroom::colors::r(lhs) * rhs,
@ -70,7 +75,8 @@ namespace sprout {
// add
//
template<typename Color1, typename Color2>
inline SPROUT_CONSTEXPR Color1 add(Color1 const& lhs, Color2 const& rhs) {
inline SPROUT_CONSTEXPR Color1
add(Color1 const& lhs, Color2 const& rhs) {
return sprout::tuples::remake<Color1>(
lhs,
sprout::darkroom::colors::r(lhs) + sprout::darkroom::colors::r(rhs),
@ -82,7 +88,8 @@ namespace sprout {
// filter
//
template<typename Color1, typename Color2>
inline SPROUT_CONSTEXPR Color1 filter(Color1 const& lhs, Color2 const& rhs) {
inline SPROUT_CONSTEXPR Color1
filter(Color1 const& lhs, Color2 const& rhs) {
return sprout::tuples::remake<Color1>(
lhs,
sprout::darkroom::colors::r(lhs) * sprout::darkroom::colors::r(rhs),
@ -95,7 +102,8 @@ namespace sprout {
// rgb_f_to_rgb
//
template<typename RGB, typename RGB_F>
inline SPROUT_CONSTEXPR RGB rgb_f_to_rgb(RGB_F const& col) {
inline SPROUT_CONSTEXPR RGB
rgb_f_to_rgb(RGB_F const& col) {
typedef typename sprout::darkroom::access::unit<RGB>::type unit_type;
return sprout::tuples::make<RGB>(
sprout::darkroom::colors::r(col) < 0 ? std::numeric_limits<unit_type>::min()

View file

@ -17,21 +17,24 @@ namespace sprout {
// z
//
template<typename T>
inline SPROUT_CONSTEXPR auto x(T&& t)
inline SPROUT_CONSTEXPR auto
x(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<0>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto y(T&& t)
inline SPROUT_CONSTEXPR auto
y(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<1>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto z(T&& t)
inline SPROUT_CONSTEXPR auto
z(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<2>(sprout::forward<T>(t)))
{
@ -66,7 +69,8 @@ namespace sprout {
// add
//
template<typename Vector1, typename Vector2>
inline SPROUT_CONSTEXPR Vector1 add(Vector1 const& lhs, Vector2 const& rhs) {
inline SPROUT_CONSTEXPR Vector1
add(Vector1 const& lhs, Vector2 const& rhs) {
return sprout::tuples::remake<Vector1>(
lhs,
sprout::darkroom::coords::x(lhs) + sprout::darkroom::coords::x(rhs),
@ -78,7 +82,8 @@ namespace sprout {
// sub
//
template<typename Vector1, typename Vector2>
inline SPROUT_CONSTEXPR Vector1 sub(Vector1 const& lhs, Vector2 const& rhs) {
inline SPROUT_CONSTEXPR Vector1
sub(Vector1 const& lhs, Vector2 const& rhs) {
return sprout::tuples::remake<Vector1>(
lhs,
sprout::darkroom::coords::x(lhs) - sprout::darkroom::coords::x(rhs),
@ -90,7 +95,8 @@ namespace sprout {
// scale
//
template<typename Vector, typename Fac>
inline SPROUT_CONSTEXPR Vector scale(Vector const& lhs, Fac const& rhs) {
inline SPROUT_CONSTEXPR Vector
scale(Vector const& lhs, Fac const& rhs) {
return sprout::tuples::remake<Vector>(
lhs,
sprout::darkroom::coords::x(lhs) * rhs,
@ -102,7 +108,8 @@ namespace sprout {
// negate
//
template<typename Vector>
inline SPROUT_CONSTEXPR Vector negate(Vector const& vec) {
inline SPROUT_CONSTEXPR Vector
negate(Vector const& vec) {
return sprout::tuples::remake<Vector>(
vec,
-sprout::darkroom::coords::x(vec),
@ -125,7 +132,8 @@ namespace sprout {
// cross
//
template<typename Vector1, typename Vector2>
inline SPROUT_CONSTEXPR Vector1 cross(Vector1 const& lhs, Vector2 const& rhs) {
inline SPROUT_CONSTEXPR Vector1
cross(Vector1 const& lhs, Vector2 const& rhs) {
return sprout::tuples::remake<Vector1>(
lhs,
sprout::darkroom::coords::y(lhs) * sprout::darkroom::coords::z(rhs)
@ -143,11 +151,8 @@ namespace sprout {
//
namespace detail {
template<typename Vector>
inline SPROUT_CONSTEXPR Vector normalize_impl(
Vector const& vec,
typename sprout::darkroom::access::unit<Vector>::type const& len
)
{
inline SPROUT_CONSTEXPR Vector
normalize_impl(Vector const& vec, typename sprout::darkroom::access::unit<Vector>::type const& len) {
return sprout::tuples::remake<Vector>(
vec,
sprout::darkroom::coords::x(vec) / len,
@ -157,7 +162,8 @@ namespace sprout {
}
} // namespace detail
template<typename Vector>
inline SPROUT_CONSTEXPR Vector normalize(Vector const& vec) {
inline SPROUT_CONSTEXPR Vector
normalize(Vector const& vec) {
return sprout::darkroom::coords::detail::normalize_impl(
vec,
sprout::darkroom::coords::length(vec)
@ -167,7 +173,8 @@ namespace sprout {
// resize
//
template<typename Vector, typename Fac>
inline SPROUT_CONSTEXPR Vector resize(Vector const& lhs, Fac const& rhs) {
inline SPROUT_CONSTEXPR Vector
resize(Vector const& lhs, Fac const& rhs) {
return sprout::darkroom::coords::detail::normalize_impl(
lhs,
sprout::darkroom::coords::length(lhs) / rhs
@ -177,7 +184,8 @@ namespace sprout {
// reflect
//
template<typename Incident, typename Normal>
inline SPROUT_CONSTEXPR Incident reflect(Incident const& incid, Normal const& nor) {
inline SPROUT_CONSTEXPR Incident
reflect(Incident const& incid, Normal const& nor) {
return sprout::darkroom::coords::sub(
incid,
sprout::darkroom::coords::scale(nor, sprout::darkroom::coords::dot(incid, nor) * 2)

View file

@ -19,35 +19,40 @@ namespace sprout {
// material
//
template<typename T>
inline SPROUT_CONSTEXPR auto does_intersect(T&& t)
inline SPROUT_CONSTEXPR auto
does_intersect(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<0>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto distance(T&& t)
inline SPROUT_CONSTEXPR auto
distance(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<1>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto point_of_intersection(T&& t)
inline SPROUT_CONSTEXPR auto
point_of_intersection(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<2>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<2>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto normal(T&& t)
inline SPROUT_CONSTEXPR auto
normal(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<3>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<3>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto material(T&& t)
inline SPROUT_CONSTEXPR auto
material(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<4>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<4>(sprout::forward<T>(t)))
{

View file

@ -26,7 +26,8 @@ namespace sprout {
: col_(col)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const&) const {
SPROUT_CONSTEXPR color_type
operator()(Intersection const& inter, Objects const&) const {
return sprout::darkroom::colors::filter(
col_,
sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter))

View file

@ -23,18 +23,21 @@ namespace sprout {
lights_type lights_;
private:
template<typename Color>
SPROUT_CONSTEXPR color_type shade_2(Color const& col) const {
SPROUT_CONSTEXPR color_type
shade_2(Color const& col) const {
return col;
}
template<typename Color1, typename Color2, typename... Tail>
SPROUT_CONSTEXPR color_type shade_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) const {
SPROUT_CONSTEXPR color_type
shade_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) const {
return shade_2(
sprout::darkroom::colors::add(col1, col2),
tail...
);
}
template<typename Intersection, typename Objects, sprout::index_t... Indexes>
SPROUT_CONSTEXPR color_type shade_1(
SPROUT_CONSTEXPR color_type
shade_1(
Intersection const& inter, Objects const& objs,
sprout::index_tuple<Indexes...>
) const
@ -46,7 +49,8 @@ namespace sprout {
: lights_(lights...)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const {
SPROUT_CONSTEXPR color_type
operator()(Intersection const& inter, Objects const& objs) const {
return shade_1(inter, objs, sprout::index_range<0, sizeof...(Lights)>::make());
}
};

View file

@ -32,11 +32,8 @@ namespace sprout {
color_type col_;
private:
template<typename Intersection>
SPROUT_CONSTEXPR color_type shade_2(
Intersection const& inter,
unit_type const& intensity
) const
{
SPROUT_CONSTEXPR color_type
shade_2(Intersection const& inter, unit_type const& intensity) const {
return sprout::darkroom::colors::mul(
sprout::darkroom::colors::filter(
col_,
@ -46,11 +43,8 @@ namespace sprout {
);
}
template<typename Intersection, typename LightRayIntersection>
SPROUT_CONSTEXPR color_type shade_1(
Intersection const& inter,
LightRayIntersection const& light_ray_inter
) const
{
SPROUT_CONSTEXPR color_type
shade_1(Intersection const& inter, LightRayIntersection const& light_ray_inter) const {
return shade_2(
inter,
!sprout::darkroom::intersects::does_intersect(light_ray_inter)
@ -67,15 +61,13 @@ namespace sprout {
);
}
public:
SPROUT_CONSTEXPR basic_parallel_light(
position_type const& dir,
color_type const& col
)
SPROUT_CONSTEXPR basic_parallel_light(position_type const& dir, color_type const& col)
: dir_(sprout::darkroom::coords::normalize(dir))
, col_(col)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const {
SPROUT_CONSTEXPR color_type
operator()(Intersection const& inter, Objects const& objs) const {
return shade_1(
inter,
sprout::darkroom::objects::intersect_list(

View file

@ -32,11 +32,8 @@ namespace sprout {
color_type col_;
private:
template<typename Intersection>
SPROUT_CONSTEXPR color_type shade_4(
Intersection const& inter,
unit_type const& intensity
) const
{
SPROUT_CONSTEXPR color_type
shade_4(Intersection const& inter, unit_type const& intensity) const {
return sprout::darkroom::colors::mul(
sprout::darkroom::colors::filter(
col_,
@ -46,10 +43,9 @@ namespace sprout {
);
}
template<typename Intersection, typename LightRayIntersection>
SPROUT_CONSTEXPR color_type shade_3(
Intersection const& inter,
position_type const& diff,
position_type const& direction,
SPROUT_CONSTEXPR color_type
shade_3(
Intersection const& inter, position_type const& diff, position_type const& direction,
LightRayIntersection const& light_ray_inter
) const
{
@ -72,13 +68,8 @@ namespace sprout {
);
}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type shade_2(
Intersection const& inter,
Objects const& objs,
position_type const& diff,
position_type const& direction
) const
{
SPROUT_CONSTEXPR color_type
shade_2(Intersection const& inter, Objects const& objs, position_type const& diff, position_type const& direction) const {
return shade_3(
inter,
diff,
@ -99,12 +90,8 @@ namespace sprout {
);
}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type shade_1(
Intersection const& inter,
Objects const& objs,
position_type const& diff
) const
{
SPROUT_CONSTEXPR color_type
shade_1(Intersection const& inter, Objects const& objs, position_type const& diff) const {
return shade_2(
inter,
objs,
@ -113,15 +100,13 @@ namespace sprout {
);
}
public:
SPROUT_CONSTEXPR basic_point_light(
position_type const& pos,
color_type const& col
)
SPROUT_CONSTEXPR basic_point_light(position_type const& pos, color_type const& col)
: pos_(pos)
, col_(col)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const {
SPROUT_CONSTEXPR color_type
operator()(Intersection const& inter, Objects const& objs) const {
return shade_1(
inter,
objs,

View file

@ -24,7 +24,8 @@ namespace sprout {
// bilinear_interpolate
//
template<typename Color, typename Unit>
inline SPROUT_CONSTEXPR Color bilinear_interpolate(
inline SPROUT_CONSTEXPR Color
bilinear_interpolate(
Color const& c00, Color const& c01, Color const& c10, Color const& c11,
Unit const& u, Unit const& v
)

View file

@ -15,14 +15,16 @@ namespace sprout {
// reflection
//
template<typename T>
inline SPROUT_CONSTEXPR auto color(T&& t)
inline SPROUT_CONSTEXPR auto
color(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<0>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto reflection(T&& t)
inline SPROUT_CONSTEXPR auto
reflection(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<1>(sprout::forward<T>(t)))
{
@ -34,13 +36,17 @@ namespace sprout {
// calc_reflection
//
template<typename Image, typename Unit>
inline SPROUT_CONSTEXPR auto calc_color(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT
inline SPROUT_CONSTEXPR auto
calc_color(Image&& t, Unit const& u, Unit const& v)
SPROUT_NOEXCEPT
-> decltype(sprout::forward<Image>(t).template operator()(u, v))
{
return sprout::forward<Image>(t).template operator()(u, v);
}
template<typename Image, typename Unit>
inline SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT
inline SPROUT_CONSTEXPR auto
calc_reflection(Image&& t, Unit const& u, Unit const& v)
SPROUT_NOEXCEPT
-> decltype(sprout::forward<Image>(t).template operator()(u, v))
{
return sprout::forward<Image>(t).template operator()(u, v);
@ -50,7 +56,8 @@ namespace sprout {
// calc_material
//
template<typename Material, typename Unit>
inline SPROUT_CONSTEXPR auto calc_material(Material const& mat, Unit const& u, Unit const& v)
inline SPROUT_CONSTEXPR auto
calc_material(Material const& mat, Unit const& u, Unit const& v)
-> decltype(sprout::tuples::make_tuple(
sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v),
sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v)

View file

@ -17,7 +17,8 @@ namespace sprout {
typedef Element result_type;
typedef Scale unit_type;
private:
static SPROUT_CONSTEXPR unit_type fmod(unit_type const& n, unit_type const& d) {
static SPROUT_CONSTEXPR unit_type
fmod(unit_type const& n, unit_type const& d) {
return n - std::intmax_t(n / d) * d;
}
private:
@ -26,24 +27,19 @@ namespace sprout {
unit_type scale_;
private:
template<typename Unit>
SPROUT_CONSTEXPR result_type calc_1(Unit const& u, Unit const& v) const {
return (u >= 0 && v >= 0) || (u < 0 && v < 0)
? elem1_
: elem2_
;
SPROUT_CONSTEXPR result_type
calc_1(Unit const& u, Unit const& v) const {
return (u >= 0 && v >= 0) || (u < 0 && v < 0) ? elem1_ : elem2_;
}
public:
SPROUT_CONSTEXPR plaid_element(
result_type const& elem1,
result_type const& elem2,
unit_type const& scale = 1
)
SPROUT_CONSTEXPR plaid_element(result_type const& elem1, result_type const& elem2, unit_type const& scale = 1)
: elem1_(elem1)
, elem2_(elem2)
, scale_(scale)
{}
template<typename Unit>
SPROUT_CONSTEXPR result_type operator()(Unit const& u, Unit const& v) const {
SPROUT_CONSTEXPR result_type
operator()(Unit const& u, Unit const& v) const {
return calc_1(
(u < 0
? scale_ + fmod(u, scale_)
@ -79,11 +75,10 @@ namespace sprout {
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::darkroom::materials::plaid_element<Color>,
sprout::darkroom::materials::plaid_element<Reflection>
> make_plaid_material_image(
Color const& col1,
Color const& col2,
Reflection const& ref1,
Reflection const& ref2
>
make_plaid_material_image(
Color const& col1, Color const& col2,
Reflection const& ref1, Reflection const& ref2
)
{
return sprout::tuples::make_tuple(
@ -95,11 +90,10 @@ namespace sprout {
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::darkroom::materials::plaid_element<Color, Unit>,
sprout::darkroom::materials::plaid_element<Reflection, Unit>
> make_plaid_material_image(
Color const& col1,
Color const& col2,
Reflection const& ref1,
Reflection const& ref2,
>
make_plaid_material_image(
Color const& col1, Color const& col2,
Reflection const& ref1, Reflection const& ref2,
Unit const& scale
)
{

View file

@ -45,22 +45,28 @@ namespace sprout {
interpolation_type::values interpolation_value_;
texture_map_placement::values placement_value_;
private:
SPROUT_CONSTEXPR bool is_nearest() const {
SPROUT_CONSTEXPR bool
is_nearest() const {
return interpolation_value_ == interpolation_type::nearest_neighbor;
}
SPROUT_CONSTEXPR bool is_bilinear() const {
SPROUT_CONSTEXPR bool
is_bilinear() const {
return interpolation_value_ == interpolation_type::bilinear;
}
SPROUT_CONSTEXPR bool is_bicubic() const {
SPROUT_CONSTEXPR bool
is_bicubic() const {
return interpolation_value_ == interpolation_type::bicubic;
}
SPROUT_CONSTEXPR bool is_tile() const {
SPROUT_CONSTEXPR bool
is_tile() const {
return placement_value_ == texture_map_placement::tile;
}
SPROUT_CONSTEXPR bool is_once() const {
SPROUT_CONSTEXPR bool
is_once() const {
return placement_value_ == texture_map_placement::once;
}
SPROUT_CONSTEXPR result_type get_color(unit_type const& x, unit_type const& y) const {
SPROUT_CONSTEXPR result_type
get_color(unit_type const& x, unit_type const& y) const {
return is_tile()
? texture_.get()(
x < 0
@ -78,11 +84,13 @@ namespace sprout {
;
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc_nearest(Unit const& x, Unit const& y) const {
SPROUT_CONSTEXPR result_type
calc_nearest(Unit const& x, Unit const& y) const {
return get_color(x, y);
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc_bilinear_1(
SPROUT_CONSTEXPR result_type
calc_bilinear_1(
Unit const& x, Unit const& x0,
Unit const& y, Unit const& y0
) const
@ -94,24 +102,24 @@ namespace sprout {
);
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc_bilinear(Unit const& x, Unit const& y) const {
SPROUT_CONSTEXPR result_type
calc_bilinear(Unit const& x, Unit const& y) const {
return calc_bilinear_1(
x, sprout::floor(x),
y, sprout::floor(y)
);
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc(Unit const& x, Unit const& y) const {
SPROUT_CONSTEXPR result_type
calc(Unit const& x, Unit const& y) const {
return is_nearest() ? calc_nearest(x, y)
: calc_bilinear(x, y)
;
}
public:
explicit SPROUT_CONSTEXPR texture_map(
texture_type const& texture,
unit_type const& scale = 1,
unit_type const& offset_u = 0,
unit_type const& offset_v = 0,
texture_type const& texture, unit_type const& scale = 1,
unit_type const& offset_u = 0, unit_type const& offset_v = 0,
result_type const& default_color = result_type(),
interpolation_type::values interpolation_value = interpolation_type::nearest_neighbor,
texture_map_placement::values placement_value = texture_map_placement::tile
@ -125,7 +133,8 @@ namespace sprout {
, placement_value_(placement_value)
{}
template<typename Unit>
SPROUT_CONSTEXPR result_type operator()(Unit const& u, Unit const& v) const {
SPROUT_CONSTEXPR result_type
operator()(Unit const& u, Unit const& v) const {
return calc(
(u - offset_u_ + scale_ / 2) / scale_ * texture_.get().width(),
(-(v - offset_v_) + scale_ / 2) / scale_ * texture_.get().height()
@ -143,10 +152,8 @@ namespace sprout {
template<typename Texture, typename Unit>
inline SPROUT_CONSTEXPR sprout::darkroom::materials::texture_map<Texture, Unit>
make_texture_map(
Texture const& texture,
Unit const& scale,
Unit const& offset_u = 0,
Unit const& offset_v = 0,
Texture const& texture, Unit const& scale,
Unit const& offset_u = 0, Unit const& offset_v = 0,
typename sprout::darkroom::materials::texture_map<Texture, Unit>::result_type const& default_color
= typename sprout::darkroom::materials::texture_map<Texture, Unit>::result_typ()
,

View file

@ -21,7 +21,8 @@ namespace sprout {
: elem_(elem)
{}
template<typename Unit>
SPROUT_CONSTEXPR result_type operator()(Unit const&, Unit const&) const {
SPROUT_CONSTEXPR result_type
operator()(Unit const&, Unit const&) const {
return elem_;
}
};
@ -40,7 +41,8 @@ namespace sprout {
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::darkroom::materials::uniform_element<Color>,
sprout::darkroom::materials::uniform_element<Reflection>
> make_uniform_material_image(Color const& col, Reflection const& ref) {
>
make_uniform_material_image(Color const& col, Reflection const& ref) {
return sprout::tuples::make_tuple(
sprout::darkroom::materials::make_uniform(col),
sprout::darkroom::materials::make_uniform(ref)

View file

@ -54,23 +54,21 @@ namespace sprout {
unit_type val_;
material_type mat_;
private:
SPROUT_CONSTEXPR bool is_x() const {
SPROUT_CONSTEXPR bool
is_x() const {
return direction_value_ == aa_plane_direction::x;
}
SPROUT_CONSTEXPR bool is_y() const {
SPROUT_CONSTEXPR bool
is_y() const {
return direction_value_ == aa_plane_direction::y;
}
SPROUT_CONSTEXPR bool is_z() const {
SPROUT_CONSTEXPR bool
is_z() const {
return direction_value_ == aa_plane_direction::z;
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_5(
int hit_side,
bool does_intersect,
unit_type distance,
position_type const& point_of_intersection
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_5(int hit_side, bool does_intersect, unit_type distance, position_type const& point_of_intersection) const {
return typename intersection<Ray>::type(
does_intersect,
distance,
@ -97,13 +95,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_4(
Ray const& ray,
int hit_side,
bool does_intersect,
unit_type distance
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_4(Ray const& ray, int hit_side, bool does_intersect, unit_type distance) const {
return intersect_5<Ray>(
hit_side,
does_intersect,
@ -114,14 +107,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_3(
Ray const& ray,
unit_type pos_v,
unit_type dir_v,
int hit_side,
bool does_intersect
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_3(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side, bool does_intersect) const {
return intersect_4(
ray,
hit_side,
@ -132,13 +119,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_2(
Ray const& ray,
unit_type pos_v,
unit_type dir_v,
int hit_side
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_2(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side) const {
return intersect_3(
ray,
pos_v,
@ -148,12 +130,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_1(
Ray const& ray,
unit_type pos_v,
unit_type dir_v
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_1(Ray const& ray, unit_type pos_v, unit_type dir_v) const {
return intersect_2(
ray,
pos_v,
@ -162,17 +140,14 @@ namespace sprout {
);
}
public:
SPROUT_CONSTEXPR basic_aa_plane(
aa_plane_direction::values direction_value,
unit_type val,
material_type const& mat
)
SPROUT_CONSTEXPR basic_aa_plane(aa_plane_direction::values direction_value, unit_type val, material_type const& mat)
: direction_value_(direction_value)
, val_(val)
, mat_(mat)
{}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect(Ray const& ray) const {
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect(Ray const& ray) const {
return intersect_1(
ray,
(is_x() ? sprout::darkroom::coords::x(sprout::darkroom::rays::position(ray))
@ -191,12 +166,7 @@ namespace sprout {
//
template<typename Material, typename Unit>
inline SPROUT_CONSTEXPR sprout::darkroom::objects::basic_aa_plane<Material>
make_aa_plane(
sprout::darkroom::objects::aa_plane_direction::values dir_val,
Unit const& val,
Material const& mat
)
{
make_aa_plane(sprout::darkroom::objects::aa_plane_direction::values dir_val, Unit const& val, Material const& mat) {
return sprout::darkroom::objects::basic_aa_plane<Material>(dir_val, val, mat);
}
} // namespace objects

View file

@ -26,8 +26,7 @@ namespace sprout {
struct intersect_list_impl {
private:
template<typename Objects, typename Ray, typename A, typename B>
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type::template intersection<Ray>::type
comp(A const& a, B const& b) const {
return sprout::darkroom::intersects::does_intersect(a)
&& sprout::darkroom::intersects::does_intersect(b)
@ -41,8 +40,7 @@ namespace sprout {
}
public:
template<typename Objects, typename Ray>
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type ::template intersection<Ray>::type
operator()(Objects const& objs, Ray const& ray) const {
return comp<Objects, Ray>(
sprout::darkroom::objects::intersect(sprout::darkroom::access::get<N>(objs), ray),
@ -54,16 +52,14 @@ namespace sprout {
struct intersect_list_impl<0> {
public:
template<typename Objects, typename Ray>
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type::template intersection<Ray>::type
operator()(Objects const& objs, Ray const& ray) const {
return sprout::darkroom::objects::intersect(sprout::darkroom::access::get<0>(objs), ray);
}
};
} // namespace detail
template<typename Objects, typename Ray>
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type::template intersection<Ray>::type
intersect_list(Objects const& objs, Ray const& ray) {
return sprout::darkroom::objects::detail::intersect_list_impl<
sprout::darkroom::access::size<Objects>::value - 1

View file

@ -45,7 +45,8 @@ namespace sprout {
position_type normal_;
private:
template<typename Vector>
SPROUT_CONSTEXPR bool within_test(Vector const& d0, Vector const& d1) {
SPROUT_CONSTEXPR bool
within_test(Vector const& d0, Vector const& d1) {
return sprout::darkroom::coords::dot(
sprout::darkroom::coords::cross(d0, d1),
normal_
@ -54,13 +55,8 @@ namespace sprout {
;
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_5(
Ray const& ray,
int hit_side,
bool does_intersect,
unit_type distance
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_5(Ray const& ray, int hit_side, bool does_intersect, unit_type distance) const {
return typename intersection<Ray>::type(
does_intersect,
distance,
@ -73,13 +69,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_4(
Ray const& ray,
position_type const& v,
int hit_side,
bool does_intersect
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_4(Ray const& ray, position_type const& v, int hit_side, bool does_intersect) const {
return intersect_5(
ray,
hit_side,
@ -90,14 +81,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_3(
Ray const& ray,
position_type const& v,
position_type const& p,
int hit_side,
bool exist_forward
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_3(Ray const& ray, position_type const& v, position_type const& p, int hit_side, bool exist_forward) const {
return intersect_4(
ray,
v,
@ -118,12 +103,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_2(
Ray const& ray,
unit_type const& t,
int hit_side
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_2(Ray const& ray, unit_type const& t, int hit_side) const {
return intersect_3(
ray,
sprout::darkroom::coords::scale(sprout::darkroom::rays::direction(ray), t),
@ -138,12 +119,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_1(
Ray const& ray,
unit_type const& xpn,
unit_type const& vn
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_1(Ray const& ray, unit_type const& xpn, unit_type const& vn) const {
return intersect_2(
ray,
xpn / vn,
@ -151,12 +128,7 @@ namespace sprout {
);
}
public:
SPROUT_CONSTEXPR basic_triangle(
material_type const& mat,
position_type const& v0,
position_type const& v1,
position_type const& v2
)
SPROUT_CONSTEXPR basic_triangle(material_type const& mat, position_type const& v0, position_type const& v1, position_type const& v2)
: mat_(mat)
, vertices_{{v0, v1, v2}}
, normal_(
@ -169,7 +141,8 @@ namespace sprout {
)
{}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect(Ray const& ray) const {
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect(Ray const& ray) const {
return intersect_1(
ray,
sprout::darkroom::coords::dot(
@ -188,13 +161,7 @@ namespace sprout {
//
template<typename Material, typename Vertex>
inline SPROUT_CONSTEXPR sprout::darkroom::objects::basic_triangle<Material, Vertex>
make_triangle(
Material const& mat,
Vertex const& v0,
Vertex const& v1,
Vertex const& v2
)
{
make_triangle(Material const& mat, Vertex const& v0, Vertex const& v1, Vertex const& v2) {
return sprout::darkroom::objects::basic_triangle<Material, Vertex>(mat, v0, v1, v2);
}
} // namespace objects

View file

@ -60,14 +60,8 @@ namespace sprout {
material_type mat_;
private:
template<typename Ray>
SPROUT_CONSTEXPR zwo_type zweitens_2(
Ray const& ray,
unit_type const& i1,
unit_type const& i2,
int hit_side,
bool does_intersect
) const
{
SPROUT_CONSTEXPR zwo_type
zweitens_2(Ray const& ray, unit_type const& i1, unit_type const& i2, int hit_side, bool does_intersect) const {
return zwo_type(
hit_side,
does_intersect,
@ -77,12 +71,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR zwo_type zweitens_1(
Ray const& ray,
unit_type const& i1,
unit_type const& i2
) const
{
SPROUT_CONSTEXPR zwo_type
zweitens_1(Ray const& ray, unit_type const& i1, unit_type const& i2) const {
return zweitens_2(
ray,
i1,
@ -95,24 +85,16 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR zwo_type zweitens(
Ray const& ray,
bool neg,
unit_type const& b,
unit_type const& det
) const
{
SPROUT_CONSTEXPR zwo_type
zweitens(Ray const& ray, bool neg, unit_type const& b, unit_type const& det) const {
return neg
? zweitens_1(ray, b - det, b + det)
: zwo_type(0, false, -1)
;
}
template<typename Ray>
SPROUT_CONSTEXPR drei_type drittens_1(
Ray const& ray,
typename sprout::darkroom::access::unit<Ray>::type point_of_intersection
) const
{
SPROUT_CONSTEXPR drei_type
drittens_1(Ray const& ray, typename sprout::darkroom::access::unit<Ray>::type point_of_intersection) const {
return drei_type(
point_of_intersection,
sprout::darkroom::coords::normalize(
@ -121,12 +103,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR drei_type drittens(
Ray const& ray,
bool neg,
unit_type const& distance
) const
{
SPROUT_CONSTEXPR drei_type
drittens(Ray const& ray, bool neg, unit_type const& distance) const {
return neg
? drittens_1(ray, sprout::darkroom::rays::point_of_intersection(ray, distance))
: drei_type(
@ -136,13 +114,8 @@ namespace sprout {
;
}
template<typename Ray, typename Vec>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_6(
Ray const& ray,
zwo_type const& zwo,
drei_type const& drei,
Vec const& normal
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_6(Ray const& ray, zwo_type const& zwo, drei_type const& drei, Vec const& normal) const {
return typename intersection<Ray>::type(
sprout::tuples::get<zw::does_intersect>(zwo),
sprout::tuples::get<zw::distance>(zwo),
@ -168,12 +141,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_5(
Ray const& ray,
zwo_type const& zwo,
drei_type const& drei
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_5(Ray const& ray, zwo_type const& zwo, drei_type const& drei) const {
return intersect_6(
ray,
zwo,
@ -182,11 +151,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_4(
Ray const& ray,
zwo_type const& zwo
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_4(Ray const& ray, zwo_type const& zwo) const {
return intersect_5(
ray,
zwo,
@ -198,12 +164,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_3(
Ray const& ray,
unit_type const& b,
unit_type const& det_sq
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_3(Ray const& ray, unit_type const& b, unit_type const& det_sq) const {
return intersect_4(
ray,
zweitens(
@ -215,12 +177,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_2(
Ray const& ray,
position_type const& v,
unit_type const& b
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_2(Ray const& ray, position_type const& v, unit_type const& b) const {
return intersect_3(
ray,
b,
@ -228,11 +186,8 @@ namespace sprout {
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_1(
Ray const& ray,
position_type const& v
) const
{
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect_1(Ray const& ray, position_type const& v) const {
return intersect_2(
ray,
v,
@ -240,17 +195,14 @@ namespace sprout {
);
}
public:
SPROUT_CONSTEXPR basic_sphere(
position_type const& pos,
radius_type rad,
material_type const& mat
)
SPROUT_CONSTEXPR basic_sphere(position_type const& pos, radius_type rad, material_type const& mat)
: pos_(pos)
, rad_(rad)
, mat_(mat)
{}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect(Ray const& ray) const {
SPROUT_CONSTEXPR typename intersection<Ray>::type
intersect(Ray const& ray) const {
return intersect_1(
ray,
sprout::darkroom::coords::sub(sprout::darkroom::rays::position(ray), pos_)

View file

@ -18,20 +18,14 @@ namespace sprout {
namespace detail {
template<
typename Pixels,
typename RayTracer,
typename Renderer,
typename Camera,
typename Objects,
typename Lights,
typename RayTracer, typename Renderer, typename Camera,
typename Objects, typename Lights,
sprout::index_t... XIndexes
>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Pixels>::value_type
generate_impl_line(
RayTracer const& raytracer,
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
RayTracer const& raytracer, Renderer const& renderer, Camera const& camera,
Objects const& objs, Lights const& lights,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
>::size_type x
@ -51,35 +45,22 @@ namespace sprout {
return sprout::make<pixel_line_type>(
sprout::darkroom::colors::rgb_f_to_rgb<pixel_type>(
raytracer.template operator()(
renderer,
camera,
objs,
lights,
x + XIndexes,
y,
width,
height,
depth_max
renderer, camera, objs, lights,
x + XIndexes, y, width, height, depth_max
)
)...
);
}
template<
typename Pixels,
typename RayTracer,
typename Renderer,
typename Camera,
typename Objects,
typename Lights,
typename RayTracer, typename Renderer, typename Camera,
typename Objects, typename Lights,
sprout::index_t... YIndexes
>
inline SPROUT_CONSTEXPR Pixels
generate_impl(
RayTracer const& raytracer,
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
RayTracer const& raytracer, Renderer const& renderer, Camera const& camera,
Objects const& objs, Lights const& lights,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
>::size_type x
@ -96,16 +77,8 @@ namespace sprout {
{
return sprout::make<Pixels>(
sprout::darkroom::pixels::detail::generate_impl_line<Pixels>(
raytracer,
renderer,
camera,
objs,
lights,
x,
y + YIndexes,
width,
height,
depth_max,
raytracer, renderer, camera, objs, lights,
x, y + YIndexes, width, height, depth_max,
sprout::index_range<
0,
sprout::container_traits<
@ -118,18 +91,12 @@ namespace sprout {
} // namespace detail
template<
typename Pixels,
typename RayTracer,
typename Renderer,
typename Camera,
typename Objects,
typename Lights
typename RayTracer, typename Renderer, typename Camera,
typename Objects, typename Lights
>
inline SPROUT_CONSTEXPR Pixels generate(
RayTracer const& raytracer,
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
RayTracer const& raytracer, Renderer const& renderer, Camera const& camera,
Objects const& objs, Lights const& lights,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
>::size_type x
@ -152,16 +119,8 @@ namespace sprout {
)
{
return sprout::darkroom::pixels::detail::generate_impl<Pixels>(
raytracer,
renderer,
camera,
objs,
lights,
x,
y,
width,
height,
depth_max,
raytracer, renderer, camera, objs, lights,
x, y, width, height, depth_max,
sprout::index_range<
0,
sprout::container_traits<Pixels>::static_size
@ -175,10 +134,7 @@ namespace sprout {
template<std::size_t Width, std::size_t Height, typename Color = sprout::darkroom::colors::rgb>
struct color_pixels {
public:
typedef sprout::array<
sprout::array<Color, Width>,
Height
> type;
typedef sprout::array<sprout::array<Color, Width>, Height> type;
};
} // namespace pixels
} // namespace darkroom

View file

@ -15,14 +15,16 @@ namespace sprout {
// direction
//
template<typename T>
inline SPROUT_CONSTEXPR auto position(T&& t)
inline SPROUT_CONSTEXPR auto
position(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<0>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
inline SPROUT_CONSTEXPR auto direction(T&& t)
inline SPROUT_CONSTEXPR auto
direction(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<1>(sprout::forward<T>(t)))
{

View file

@ -13,7 +13,8 @@ namespace sprout {
// normal_to_color
//
template<typename Color, typename Normal>
inline SPROUT_CONSTEXPR Color normal_to_color(Normal const& nor) {
inline SPROUT_CONSTEXPR Color
normal_to_color(Normal const& nor) {
return sprout::tuples::make<Color>(
0.5 + sprout::darkroom::coords::x(nor) * 0.5,
0.5 + sprout::darkroom::coords::y(nor) * 0.5,
@ -27,7 +28,8 @@ namespace sprout {
class direction_gradation {
public:
template<typename TargetColor, typename Vector>
SPROUT_CONSTEXPR TargetColor operator()(Vector const& dir) const {
SPROUT_CONSTEXPR TargetColor
operator()(Vector const& dir) const {
return sprout::darkroom::renderers::normal_to_color<TargetColor>(dir);
}
};
@ -57,7 +59,8 @@ namespace sprout {
: color_(color)
{}
template<typename TargetColor, typename Vector>
SPROUT_CONSTEXPR TargetColor operator()(Vector const&) const {
SPROUT_CONSTEXPR TargetColor
operator()(Vector const&) const {
return color_;
}
};

View file

@ -25,29 +25,20 @@ namespace sprout {
private:
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection,
typename Tracer,
typename Camera, typename Objects, typename Lights,
typename Ray, typename Intersection, typename Tracer,
typename Direction
>
SPROUT_CONSTEXPR Color color_1(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
Intersection const& inter,
Tracer const& tracer,
SPROUT_CONSTEXPR Color
color_1(
Camera const& camera, Objects const& objs, Lights const& lights,
Ray const& ray, Intersection const& inter, Tracer const& tracer,
std::size_t depth_max,
Direction const& reflect_dir
) const
{
return tracer.template operator()<Color>(
camera,
objs,
lights,
camera, objs, lights,
sprout::tuples::remake<Ray>(
ray,
sprout::darkroom::coords::add(
@ -70,20 +61,13 @@ namespace sprout {
public:
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection,
typename Tracer
typename Camera, typename Objects, typename Lights,
typename Ray, typename Intersection, typename Tracer
>
SPROUT_CONSTEXPR Color operator()(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
Intersection const& inter,
Tracer const& tracer,
SPROUT_CONSTEXPR Color
operator()(
Camera const& camera, Objects const& objs, Lights const& lights,
Ray const& ray, Intersection const& inter, Tracer const& tracer,
std::size_t depth_max
) const
{
@ -95,12 +79,8 @@ namespace sprout {
&& sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))
> std::numeric_limits<reflection_type>::epsilon()
? color_1<Color>(
camera,
objs,
lights,
ray,
inter,
tracer,
camera, objs, lights,
ray, inter, tracer,
depth_max,
sprout::darkroom::coords::reflect(
sprout::darkroom::rays::direction(ray),
@ -121,16 +101,11 @@ namespace sprout {
private:
infinity_color_type infinity_color_;
private:
template<
typename Color,
typename Ray,
typename Intersection
>
SPROUT_CONSTEXPR Color color_3(
Ray const& ray,
Intersection const& inter,
Color const& diffuse_color,
Color const& mirror_color
template<typename Color, typename Ray, typename Intersection>
SPROUT_CONSTEXPR Color
color_3(
Ray const& ray, Intersection const& inter,
Color const& diffuse_color, Color const& mirror_color
) const
{
return sprout::darkroom::intersects::does_intersect(inter)
@ -149,61 +124,40 @@ namespace sprout {
}
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection
typename Camera, typename Objects, typename Lights,
typename Ray, typename Intersection
>
SPROUT_CONSTEXPR Color color_2(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
std::size_t depth_max,
Intersection const& inter,
SPROUT_CONSTEXPR Color
color_2(
Camera const& camera, Objects const& objs, Lights const& lights,
Ray const& ray, std::size_t depth_max, Intersection const& inter,
Color const& diffuse_color
) const
{
return color_3<Color>(
ray,
inter,
ray, inter,
diffuse_color,
sprout::darkroom::renderers::whitted_mirror().template operator()<Color>(
camera,
objs,
lights,
ray,
inter,
*this,
camera, objs, lights,
ray, inter, *this,
depth_max
)
);
}
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection
typename Camera, typename Objects, typename Lights,
typename Ray, typename Intersection
>
SPROUT_CONSTEXPR Color color_1(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
std::size_t depth_max,
Intersection const& inter
SPROUT_CONSTEXPR Color
color_1(
Camera const& camera, Objects const& objs, Lights const& lights,
Ray const& ray, std::size_t depth_max, Intersection const& inter
) const
{
return color_2<Color>(
camera,
objs,
lights,
ray,
depth_max,
inter,
camera, objs, lights,
ray, depth_max, inter,
lights.template operator()(inter, objs)
);
}
@ -215,27 +169,16 @@ namespace sprout {
explicit SPROUT_CONSTEXPR whitted_style(infinity_color_type const& infinity_color)
: infinity_color_(infinity_color)
{}
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray
>
SPROUT_CONSTEXPR Color operator()(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
std::size_t depth_max
template<typename Color, typename Camera, typename Objects, typename Lights, typename Ray>
SPROUT_CONSTEXPR Color
operator()(
Camera const& camera, Objects const& objs, Lights const& lights,
Ray const& ray, std::size_t depth_max
) const
{
return color_1<Color>(
camera,
objs,
lights,
ray,
depth_max,
camera, objs, lights,
ray, depth_max,
sprout::darkroom::objects::intersect_list(objs, ray)
);
}

View file

@ -61,11 +61,7 @@ namespace sprout {
pixels_type pixels_;
public:
template<typename... Elems>
SPROUT_CONSTEXPR image_type(
unsigned long image_format,
unsigned long pixel_format,
Elems const&... elems
)
SPROUT_CONSTEXPR image_type(unsigned long image_format, unsigned long pixel_format, Elems const&... elems)
: pixels_{{
color_type(
static_cast<color_component_type>((elems >> 16) & 0xFF) / 0xFF,
@ -76,16 +72,20 @@ namespace sprout {
{
static_assert(sizeof...(Elems) == static_width * static_height, "image_type<>: unmatch image size");
}
SPROUT_CONSTEXPR value_type const& operator()(size_type x, size_type y) const {
SPROUT_CONSTEXPR value_type const&
operator()(size_type x, size_type y) const {
return pixels_[y * static_width + x];
}
SPROUT_CONSTEXPR size_type width() const {
SPROUT_CONSTEXPR size_type
width() const {
return static_width;
}
SPROUT_CONSTEXPR size_type height() const {
SPROUT_CONSTEXPR size_type
height() const {
return static_height;
}
SPROUT_CONSTEXPR pixels_type const& pixels() const {
SPROUT_CONSTEXPR pixels_type const&
pixels() const {
return pixels_;
}
};

View file

@ -16,29 +16,15 @@ namespace sprout {
public:
typedef Color color_type;
public:
template<
typename Renderer,
typename Camera,
typename Objects,
typename Lights,
typename Unit2D
>
template<typename Renderer, typename Camera, typename Objects, typename Lights, typename Unit2D>
SPROUT_CONSTEXPR color_type operator()(
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
Unit2D const& x,
Unit2D const& y,
Unit2D const& width,
Unit2D const& height,
Renderer const& renderer, Camera const& camera, Objects const& objs, Lights const& lights,
Unit2D const& x, Unit2D const& y, Unit2D const& width, Unit2D const& height,
std::size_t depth_max = 8
) const
{
return renderer.template operator()<color_type>(
camera,
objs,
lights,
camera, objs, lights,
camera.template operator()(x, y, width, height),
depth_max
);

View file

@ -11,12 +11,8 @@ namespace sprout {
// count_n
//
template<typename InputIterator, typename Size, typename T>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type count_n(
InputIterator first,
Size n,
T const& value
)
{
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
count_n(InputIterator first, Size n, T const& value) {
return n == 0 ? 0
: (*first == value ? 1 : 0) + sprout::detail::count_n(sprout::next(first), n - 1, value)
;

View file

@ -11,12 +11,8 @@ namespace sprout {
// count_n_if
//
template<typename InputIterator, typename Size, typename Predicate>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type count_n_if(
InputIterator first,
Size n,
Predicate pred
)
{
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
count_n_if(InputIterator first, Size n, Predicate pred) {
return n == 0 ? 0
: (pred(*first) ? 1 : 0) + sprout::detail::count_n_if(sprout::next(first), n - 1, pred)
;

View file

@ -8,17 +8,15 @@
namespace sprout {
namespace detail {
template<typename InputIterator>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type overlap_count_impl(
InputIterator first,
InputIterator last,
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
overlap_count_impl(
InputIterator first, InputIterator last,
typename std::iterator_traits<InputIterator>::value_type const& value,
typename std::iterator_traits<InputIterator>::difference_type current = 0
)
{
return first == last
? 0
: *first == value
? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, value)
return first == last ? 0
: *first == value ? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, value)
: sprout::detail::overlap_count_impl(sprout::next(first), last, *first)
;
}
@ -26,29 +24,22 @@ namespace sprout {
// overlap_count
//
template<typename InputIterator>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type overlap_count(
InputIterator first,
InputIterator last
)
{
return first == last
? 0
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
overlap_count(InputIterator first, InputIterator last) {
return first == last ? 0
: sprout::detail::overlap_count_impl(sprout::next(first), last, *first)
;
}
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type overlap_count_impl(
InputIterator first,
InputIterator last,
Predicate pred,
typename std::iterator_traits<InputIterator>::value_type const& value
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
overlap_count_impl(
InputIterator first, InputIterator last,
Predicate pred, typename std::iterator_traits<InputIterator>::value_type const& value
)
{
return first == last
? 0
: pred(*first, value)
? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, pred, value)
return first == last ? 0
: pred(*first, value) ? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, pred, value)
: sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first)
;
}
@ -56,14 +47,9 @@ namespace sprout {
// overlap_count
//
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type overlap_count(
InputIterator first,
InputIterator last,
Predicate pred
)
{
return first == last
? 0
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
overlap_count(InputIterator first, InputIterator last, Predicate pred) {
return first == last ? 0
: sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first)
;
}

View file

@ -11,11 +11,10 @@ namespace sprout {
// set_overlap_count
//
template<typename InputIterator1, typename InputIterator2, typename Compare>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator1>::difference_type set_overlap_count(
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2,
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator1>::difference_type
set_overlap_count(
InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare comp
)
{
@ -32,11 +31,10 @@ namespace sprout {
// set_overlap_count
//
template<typename InputIterator1, typename InputIterator2>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator1>::difference_type set_overlap_count(
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator1>::difference_type
set_overlap_count(
InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2
)
{
return first1 != last1 && first2 != last2

View file

@ -9,21 +9,24 @@
namespace sprout {
namespace detail {
template<typename Elem, typename IntType>
inline SPROUT_CONSTEXPR Elem int_to_char(IntType val, int base){
inline SPROUT_CONSTEXPR Elem
int_to_char(IntType val, int base) {
return val >= 0 && val < 10 ? static_cast<Elem>('0') + val
: val >= 10 && val < static_cast<IntType>(base) ? static_cast<Elem>('a') + (val - 10)
: throw std::invalid_argument("value out of bounds")
;
}
template<typename Elem, typename IntType>
inline SPROUT_CONSTEXPR Elem int_to_char(IntType val){
inline SPROUT_CONSTEXPR Elem
int_to_char(IntType val) {
return val >= 0 && val < 10 ? static_cast<Elem>('0') + val
: throw std::invalid_argument("value out of bounds")
;
}
template<typename IntType, typename Elem>
inline SPROUT_CONSTEXPR IntType char_to_int(Elem c, int base){
inline SPROUT_CONSTEXPR IntType
char_to_int(Elem c, int base) {
return sprout::ascii::isdigit(c) && c - static_cast<Elem>('0') < base ? c - static_cast<Elem>('0')
: sprout::ascii::islower(c) && c - static_cast<Elem>('a') + 10 < base ? c - static_cast<Elem>('a') + 10
: sprout::ascii::isupper(c) && c - static_cast<Elem>('A') + 10 < base ? c - static_cast<Elem>('A') + 10
@ -31,7 +34,8 @@ namespace sprout {
;
}
template<typename IntType, typename Elem>
inline SPROUT_CONSTEXPR IntType char_to_int(Elem c){
inline SPROUT_CONSTEXPR IntType
char_to_int(Elem c) {
return sprout::ascii::isdigit(c) ? c - static_cast<Elem>('0')
: static_cast<IntType>(-1)
;

Some files were not shown because too many files have changed in this diff Show more