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

View file

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

View file

@ -16,27 +16,33 @@ namespace sprout {
// operator>= // operator>=
// //
template<typename T, std::size_t N> 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()); return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
template<typename T, std::size_t N> 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); return !(lhs == rhs);
} }
template<typename T, std::size_t N> 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()); return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
} }
template<typename T, std::size_t N> 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; return rhs < lhs;
} }
template<typename T, std::size_t N> 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); return !(rhs < lhs);
} }
template<typename T, std::size_t N> 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); return !(lhs < rhs);
} }
} // namespace sprout } // namespace sprout

View file

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

View file

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

View file

@ -31,7 +31,8 @@ namespace sprout {
SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT; SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT;
public: public:
template <typename IntType> 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) return (sprout::detail::bit_rev<next_size>().template operator()(x) << shift_bits)
| (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> { struct bit_rev<1> {
public: public:
template<typename IntType> 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)]; 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< SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<IntType>::value, std::is_integral<IntType>::value,
IntType IntType
>::type bit_reverse(IntType x) { >::type
bit_reverse(IntType x) {
typedef typename std::make_unsigned<IntType>::type unsigned_type; typedef typename std::make_unsigned<IntType>::type unsigned_type;
return static_cast<IntType>( return static_cast<IntType>(
sprout::detail::bit_rev<sizeof(IntType)>().template operator()<unsigned_type>(x) sprout::detail::bit_rev<sizeof(IntType)>().template operator()<unsigned_type>(x)
@ -66,7 +69,8 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::enable_if< inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<IntType>::value, std::is_integral<IntType>::value,
IntType 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; typedef typename std::make_unsigned<IntType>::type unsigned_type;
return length <= sizeof(IntType) * CHAR_BIT return length <= sizeof(IntType) * CHAR_BIT
? static_cast<IntType>( ? static_cast<IntType>(

View file

@ -7,7 +7,8 @@
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
namespace sprout { 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; return j < 0 ? -j : j;
} }
} // namespace sprout } // namespace sprout

View file

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

View file

@ -10,19 +10,23 @@ namespace sprout {
// //
// strtoimax // 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); return sprout::str_to_int<std::intmax_t>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<std::intmax_t>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<std::intmax_t>(str, base);
} }
template<typename Char> 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); return sprout::str_to_int<std::intmax_t>(str, base);
} }
} // namespace sprout } // namespace sprout

View file

@ -10,19 +10,23 @@ namespace sprout {
// //
// strtoumax // 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); return sprout::str_to_int<std::uintmax_t>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<std::uintmax_t>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<std::uintmax_t>(str, base);
} }
template<typename Char> 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); return sprout::str_to_int<std::uintmax_t>(str, base);
} }
} // namespace sprout } // namespace sprout

View file

@ -1,588 +1,12 @@
#ifndef SPROUT_COMPLEX_HPP #ifndef SPROUT_COMPLEX_HPP
#define SPROUT_COMPLEX_HPP #define SPROUT_COMPLEX_HPP
#include <iosfwd>
#include <ios>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/math/constants.hpp> #include <sprout/complex/complex.hpp>
#include <sprout/math/abs.hpp> #include <sprout/complex/operators.hpp>
#include <sprout/math/sin.hpp> #include <sprout/complex/values.hpp>
#include <sprout/math/cos.hpp> #include <sprout/complex/transcendentals.hpp>
#include <sprout/math/atan2.hpp> #include <sprout/complex/hash.hpp>
#include <sprout/math/sinh.hpp> #include <sprout/complex/nearest.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
#endif // #ifndef SPROUT_COMPLEX_HPP #endif // #ifndef SPROUT_COMPLEX_HPP

View file

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

View file

@ -11,7 +11,8 @@ namespace sprout {
// hash_value // hash_value
// //
template<typename T> 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()); return sprout::hash_values(v.real(), v.imag());
} }
} // namespace sprout } // namespace sprout

View file

@ -10,19 +10,23 @@
namespace sprout { namespace sprout {
template<typename T> 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())); return sprout::complex<T>(sprout::ceil(x.real()), sprout::ceil(x.imag()));
} }
template<typename T> 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())); return sprout::complex<T>(sprout::floor(x.real()), sprout::floor(x.imag()));
} }
template<typename T> 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())); return sprout::complex<T>(sprout::trunc(x.real()), sprout::trunc(x.imag()));
} }
template<typename T> 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())); return sprout::complex<T>(sprout::round(x.real()), sprout::round(x.imag()));
} }
} // namespace sprout } // namespace sprout

View file

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

View file

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

View file

@ -11,36 +11,44 @@
namespace sprout { namespace sprout {
template<typename T> 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: // 26.4.7, values:
template<typename T> 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(); return x.real();
} }
template<typename T> 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(); return x.imag();
} }
template<typename T> 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)); return sprout::sqrt(sprout::norm(x));
} }
template<typename T> 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()); return sprout::atan2(x.imag(), x.real());
} }
template<typename T> 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(); return x.real() * x.real() + x.imag() * x.imag();
} }
template<typename T> 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()); return sprout::complex<T>(x.real(), -x.imag());
} }
namespace detail { namespace detail {
template<typename T> 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>( return sprout::complex<T>(
T(2) * x.real() / den, T(2) * x.real() / den,
T(2) * x.imag() / den T(2) * x.imag() / den
@ -48,14 +56,16 @@ namespace sprout {
} }
} // detail } // detail
template<typename T> 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( return sprout::detail::proj_impl(
x, x,
sprout::norm(x) + T(1) sprout::norm(x) + T(1)
); );
} }
template<typename T> 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)); return sprout::complex<T>(rho * sprout::cos(theta), rho * sprout::sin(theta));
} }
} // namespace sprout } // namespace sprout

View file

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

View file

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

View file

@ -8,57 +8,13 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/has_xxx.hpp> #include <sprout/type_traits/has_xxx.hpp>
#include <sprout/type_traits/inherit_if_xxx.hpp> #include <sprout/type_traits/inherit_if_xxx.hpp>
#include <sprout/container/detail/array_like.hpp>
namespace sprout { namespace sprout {
template<typename Container> template<typename Container>
struct container_traits; struct container_traits;
namespace detail { 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_value_type
// has_iterator // has_iterator
@ -438,7 +394,8 @@ namespace sprout {
template<typename Container> template<typename Container>
struct container_nosy_fixed_size_impl<Container, true> { struct container_nosy_fixed_size_impl<Container, true> {
public: 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; return sprout::detail::container_nosy_static_size<Container>::static_size;
} }
}; };
@ -447,7 +404,7 @@ namespace sprout {
: public sprout::detail::container_nosy_fixed_size_impl< : public sprout::detail::container_nosy_fixed_size_impl<
Container, Container,
sprout::detail::has_container_nosy_static_size<Container>::value sprout::detail::has_container_nosy_static_size<Container>::value
> >
{}; {};
// //
@ -482,7 +439,8 @@ namespace sprout {
public: public:
SPROUT_STATIC_CONSTEXPR size_type static_size = N ; SPROUT_STATIC_CONSTEXPR size_type static_size = N ;
public: public:
static SPROUT_CONSTEXPR size_type fixed_size() { static SPROUT_CONSTEXPR size_type
fixed_size() {
return static_size; return static_size;
} }
}; };

View file

@ -5,6 +5,7 @@
#include <type_traits> #include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/container/container_traits.hpp> #include <sprout/container/container_traits.hpp>
#include <sprout/container/detail/array_like.hpp>
namespace sprout { namespace sprout {
// //
@ -14,31 +15,6 @@ namespace sprout {
struct container_transform_traits; struct container_transform_traits;
namespace detail { 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> template<typename Container, typename sprout::container_traits<Container>::size_type Size>
struct default_array_rebind_size; struct default_array_rebind_size;
template< template<
@ -57,7 +33,7 @@ namespace sprout {
template<typename Container> template<typename Container>
struct inherit_default_rebind_size< struct inherit_default_rebind_size<
Container, 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: public:
template<typename sprout::container_traits<Container>::size_type Size> template<typename sprout::container_traits<Container>::size_type Size>

View file

@ -13,7 +13,8 @@ namespace sprout {
template<typename Container> template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_construct_traits< inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<
typename std::remove_reference<Container>::type 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; typedef typename std::remove_reference<Container>::type container_type;
return sprout::container_construct_traits<container_type>::deep_copy(sprout::forward<Container>(cont)); 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 // fixed_size
// //
template<typename Container> 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(); return sprout::container_traits<Container>::fixed_size();
} }
} // namespace sprout } // namespace sprout

View file

@ -12,7 +12,8 @@ namespace sprout {
// get_internal // get_internal
// //
template<typename Container> 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; typedef typename std::remove_reference<Container>::type container_type;
return sprout::sub_container_traits<container_type>::get_internal(sprout::forward<Container>(cont)); 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 std::remove_reference<
typename sprout::containers::internal<Container&>::type typename sprout::containers::internal<Container&>::type
>::type >::type
>::iterator internal_begin(Container& cont) { >::iterator
internal_begin(Container& cont) {
return sprout::begin(sprout::get_internal(cont)); return sprout::begin(sprout::get_internal(cont));
} }
template<typename Container> template<typename Container>
@ -26,7 +27,8 @@ namespace sprout {
typename std::remove_reference< typename std::remove_reference<
typename sprout::containers::internal<Container const&>::type typename sprout::containers::internal<Container const&>::type
>::type >::type
>::const_iterator internal_begin(Container const& cont) { >::const_iterator
internal_begin(Container const& cont) {
return sprout::begin(sprout::get_internal(cont)); return sprout::begin(sprout::get_internal(cont));
} }
@ -38,7 +40,8 @@ namespace sprout {
typename std::remove_reference< typename std::remove_reference<
typename sprout::containers::internal<Container const&>::type typename sprout::containers::internal<Container const&>::type
>::type >::type
>::const_iterator internal_cbegin(Container const& cont) { >::const_iterator
internal_cbegin(Container const& cont) {
return sprout::begin(sprout::get_internal(cont)); return sprout::begin(sprout::get_internal(cont));
} }
} // namespace sprout } // namespace sprout

View file

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

View file

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

View file

@ -10,7 +10,8 @@ namespace sprout {
// make // make
// //
template<typename Container, typename... Args> 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)...); return sprout::container_construct_traits<Container>::make(sprout::forward<Args>(args)...);
} }
} // namespace sprout } // namespace sprout

View file

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

View file

@ -15,7 +15,7 @@ namespace sprout {
: public std::integral_constant< : public std::integral_constant<
typename sprout::container_traits<Container>::size_type, typename sprout::container_traits<Container>::size_type,
sprout::container_traits<Container>::static_size sprout::container_traits<Container>::static_size
> >
{}; {};
} // namespace containers } // namespace containers
} // namespace sprout } // namespace sprout

View file

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

View file

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

View file

@ -9,7 +9,8 @@ namespace sprout {
// atof // atof
// //
template<typename Char> 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); return sprout::str_to_float<double>(str);
} }
} // namespace sprout } // namespace sprout

View file

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

View file

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

View file

@ -8,11 +8,13 @@ namespace sprout {
// //
// atoll // 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); return sprout::ascii_to_int<long long>(str);
} }
template<typename Char> 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); return sprout::ascii_to_int<long long>(str);
} }
} // namespace sprout } // namespace sprout

View file

@ -34,7 +34,8 @@ namespace sprout {
sprout::detail::div_t_traits<T>::offsetof_quot == 0 sprout::detail::div_t_traits<T>::offsetof_quot == 0
>::type = sprout::enabler >::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}; return {numer / denom, numer % denom};
} }
@ -44,29 +45,35 @@ namespace sprout {
sprout::detail::div_t_traits<T>::offsetof_rem == 0 sprout::detail::div_t_traits<T>::offsetof_rem == 0
>::type = sprout::enabler >::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}; return {numer % denom, numer / denom};
} }
} // namespace detail } // namespace detail
// 7.20.6.2 div<69>Cldiv<69>CyÑ lldiv ŠÖ<C5A0> // 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); 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); 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); 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); 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); return sprout::lldiv(numer, denom);
} }
} // namespace sprout } // namespace sprout

View file

@ -13,7 +13,8 @@
namespace sprout { namespace sprout {
namespace detail { namespace detail {
template<typename FloatType, typename CStrIterator> 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, CStrIterator str,
bool negative, bool negative,
FloatType number = FloatType(), FloatType number = FloatType(),
@ -38,7 +39,8 @@ namespace sprout {
; ;
} }
template<typename FloatType, typename CStrIterator> 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, CStrIterator str,
bool negative, bool negative,
FloatType number = FloatType(), FloatType number = FloatType(),
@ -63,7 +65,8 @@ namespace sprout {
; ;
} }
template<typename FloatType, typename CStrIterator> 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, CStrIterator str,
bool negative, bool negative,
FloatType number = FloatType(), FloatType number = FloatType(),
@ -95,7 +98,8 @@ namespace sprout {
; ;
} }
template<typename FloatType, typename CStrIterator> 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, CStrIterator str,
bool negative, bool negative,
FloatType number = FloatType(), FloatType number = FloatType(),
@ -134,7 +138,8 @@ namespace sprout {
; ;
} }
template<typename FloatType, typename CStrIterator> 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, CStrIterator str,
bool negative, bool negative,
FloatType number = FloatType(), FloatType number = FloatType(),
@ -155,7 +160,8 @@ namespace sprout {
; ;
} }
template<typename FloatType, typename CStrIterator> 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, CStrIterator str,
bool negative, bool negative,
FloatType number = FloatType(), FloatType number = FloatType(),
@ -185,7 +191,8 @@ namespace sprout {
} }
template<typename FloatType, typename CStrIterator> template<typename FloatType, typename CStrIterator>
inline SPROUT_CONSTEXPR FloatType str_to_float_impl( inline SPROUT_CONSTEXPR FloatType
str_to_float_impl(
CStrIterator str, CStrIterator str,
bool negative, bool negative,
FloatType number = FloatType(), FloatType number = FloatType(),
@ -214,7 +221,8 @@ namespace sprout {
; ;
} }
template<typename FloatType, typename CStrIterator> 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) return sprout::ascii::isspace(*str)
? sprout::detail::str_to_float<FloatType>(sprout::next(str)) ? sprout::detail::str_to_float<FloatType>(sprout::next(str))
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('-') : *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('-')
@ -225,7 +233,8 @@ namespace sprout {
; ;
} }
template<typename FloatType, typename CStrIterator, typename CharPtr> 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) 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, float>::value ? std::strtof(&*str, endptr)
: std::is_same<typename std::remove_cv<FloatType>::type, double>::value ? std::strtod(&*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 // str_to_float
// //
template<typename FloatType, typename Char, typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler> 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); 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> 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); 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> 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); return sprout::detail::str_to_float<FloatType>(str);
} }
} // namespace sprout } // namespace sprout

View file

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

View file

@ -10,15 +10,18 @@ namespace sprout {
// strtod // strtod
// //
template<typename Char> 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); return sprout::str_to_float<double>(str, endptr);
} }
template<typename Char> 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); return sprout::str_to_float<double>(str);
} }
template<typename Char> 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); return sprout::str_to_float<double>(str);
} }
} // namespace sprout } // namespace sprout

View file

@ -10,15 +10,18 @@ namespace sprout {
// strtof // strtof
// //
template<typename Char> 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); return sprout::str_to_float<float>(str, endptr);
} }
template<typename Char> 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); return sprout::str_to_float<float>(str);
} }
template<typename Char> 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); return sprout::str_to_float<float>(str);
} }
} // namespace sprout } // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
// //
// strtol // 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); return sprout::str_to_int<long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<long>(str, base);
} }
template<typename Char> 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); return sprout::str_to_int<long>(str, base);
} }
} // namespace sprout } // namespace sprout

View file

@ -10,15 +10,18 @@ namespace sprout {
// strtold // strtold
// //
template<typename Char> 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); return sprout::str_to_float<long double>(str, endptr);
} }
template<typename Char> 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); return sprout::str_to_float<long double>(str);
} }
template<typename Char> 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); return sprout::str_to_float<long double>(str);
} }
} // namespace sprout } // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
// //
// strtol // 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); return sprout::str_to_int<long long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<long long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<long long>(str, base);
} }
template<typename Char> 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); return sprout::str_to_int<long long>(str, base);
} }
} // namespace sprout } // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
// //
// strtoul // 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); return sprout::str_to_int<unsigned long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<unsigned long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<unsigned long>(str, base);
} }
template<typename Char> 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); return sprout::str_to_int<unsigned long>(str, base);
} }
} // namespace sprout } // namespace sprout

View file

@ -9,19 +9,23 @@ namespace sprout {
// //
// strtoul // 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); return sprout::str_to_int<unsigned long long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<unsigned long long>(str, endptr, base);
} }
template<typename Char> 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); return sprout::str_to_int<unsigned long long>(str, base);
} }
template<typename Char> 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); return sprout::str_to_int<unsigned long long>(str, base);
} }
} // namespace sprout } // namespace sprout

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
namespace detail { 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 return !n ? 0
: *s == c ? s : *s == c ? s
: sprout::detail::memchr_impl(s + 1, c, n - 1) : sprout::detail::memchr_impl(s + 1, c, n - 1)
@ -17,11 +18,13 @@ namespace sprout {
} // namespace detail } // namespace detail
// 7.21.5.1 memchr ŠÖ<C5A0> // 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); 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*>( return const_cast<void*>(
sprout::detail::memchr_impl(static_cast<unsigned char*>(s), static_cast<unsigned char>(c), n) 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) // Copyright (C) 2011 RiSK (sscrisk)
namespace detail { 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 return !n ? 0
: *s1 == *s2 ? sprout::detail::memcmp_impl(s1 + 1, s2 + 1, n - 1) : *s1 == *s2 ? sprout::detail::memcmp_impl(s1 + 1, s2 + 1, n - 1)
: *s1 - *s2 : *s1 - *s2
@ -17,7 +18,8 @@ namespace sprout {
} // namespace detail } // namespace detail
// 7.21.4.1 memcmp ŠÖ<C5A0> // 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( return sprout::detail::memcmp_impl(
static_cast<unsigned char const*>(s1), static_cast<unsigned char const*>(s1),
static_cast<unsigned char const*>(s2), static_cast<unsigned char const*>(s2),

View file

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

View file

@ -7,7 +7,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.2 strcmp ŠÖ<C5A0> // 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 return !*s1 && !*s2 ? 0
: !*s1 ? -1 : !*s1 ? -1
: !*s2 ? 1 : !*s2 ? 1

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.3 strcoll ŠÖ<C5A0> // 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); return sprout::strcmp(s1, s2);
} }
} // namespace sprout } // namespace sprout

View file

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

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
namespace detail { 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 : return !*s ? n :
sprout::detail::strlen_impl(s + 1, n + 1) sprout::detail::strlen_impl(s + 1, n + 1)
; ;
@ -16,7 +17,8 @@ namespace sprout {
} // namespace detail } // namespace detail
// 7.21.6.3 strlen ŠÖ<C5A0> // 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); return sprout::detail::strlen_impl(s, 0);
} }
} // namespace sprout } // namespace sprout

View file

@ -8,7 +8,8 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.4 strncmp ŠÖ<C5A0> // 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 return !n || (!*s1 && !*s2) ? 0
: !*s1 ? -1 : !*s1 ? -1
: !*s2 ? 1 : !*s2 ? 1

View file

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

View file

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

View file

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

View file

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

View file

@ -180,46 +180,60 @@ namespace sprout {
} // namespace detail } // namespace detail
#define SPROUT_CTYPE_ASCII_DECL(CHAR_TYPE, PREFIX) \ #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); \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper ? c - (0x61 - 0x41) : c; \
} }

View file

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

View file

@ -6,7 +6,8 @@
namespace sprout { namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // 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 return !*s1 && !*s2 ? 0
: !*s1 ? -1 : !*s1 ? -1
: !*s2 ? 1 : !*s2 ? 1

View file

@ -7,7 +7,8 @@
namespace sprout { namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // 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); return sprout::wcscmp(s1, s2);
} }
} // namespace sprout } // namespace sprout

View file

@ -9,14 +9,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
namespace detail { 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 return !*s1 || sprout::wcschr(s2, *s1) ? n
: sprout::detail::wcscspn_impl(s1 + 1, s2, n + 1) : sprout::detail::wcscspn_impl(s1 + 1, s2, n + 1)
; ;
} }
} // amespace detail } // 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); return sprout::detail::wcscspn_impl(s1, s2, 0);
} }
} // namespace sprout } // namespace sprout

View file

@ -8,14 +8,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
namespace detail { 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 : return !*s ? n :
sprout::detail::wcslen_impl(s + 1, n + 1) sprout::detail::wcslen_impl(s + 1, n + 1)
; ;
} }
} // namespace detail } // 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); return sprout::detail::wcslen_impl(s, 0);
} }
} // namespace sprout } // namespace sprout

View file

@ -7,7 +7,8 @@
namespace sprout { namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // 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 return !n || (!*s1 && !*s2) ? 0
: !*s1 ? -1 : !*s1 ? -1
: !*s2 ? 1 : !*s2 ? 1

View file

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

View file

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

View file

@ -9,14 +9,16 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
namespace detail { 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 return !*s1 || !sprout::wcschr(s2, *s1) ? n
: sprout::detail::wcsspn_impl(s1 + 1, s2, n + 1) : sprout::detail::wcsspn_impl(s1 + 1, s2, n + 1)
; ;
} }
} // namespace detail } // 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); return sprout::detail::wcsspn_impl(s1, s2, 0);
} }
} // namespace sprout } // namespace sprout

View file

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

View file

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

View file

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

View file

@ -34,9 +34,10 @@ namespace sprout {
// get // get
// //
template<std::size_t I, typename T> template<std::size_t I, typename T>
inline SPROUT_CONSTEXPR auto get(T&& t) inline SPROUT_CONSTEXPR auto
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<I>(sprout::forward<T>(t)))) get(T&& t)
-> decltype(sprout::tuples::get<I>(sprout::forward<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)))
{ {
return sprout::tuples::get<I>(sprout::forward<T>(t)); return sprout::tuples::get<I>(sprout::forward<T>(t));
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -26,7 +26,8 @@ namespace sprout {
: col_(col) : col_(col)
{} {}
template<typename Intersection, typename Objects> 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( return sprout::darkroom::colors::filter(
col_, col_,
sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter)) sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter))

View file

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

View file

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

View file

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

View file

@ -24,7 +24,8 @@ namespace sprout {
// bilinear_interpolate // bilinear_interpolate
// //
template<typename Color, typename Unit> 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, Color const& c00, Color const& c01, Color const& c10, Color const& c11,
Unit const& u, Unit const& v Unit const& u, Unit const& v
) )

View file

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

View file

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

View file

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

View file

@ -21,7 +21,8 @@ namespace sprout {
: elem_(elem) : elem_(elem)
{} {}
template<typename Unit> 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_; return elem_;
} }
}; };
@ -40,7 +41,8 @@ namespace sprout {
inline SPROUT_CONSTEXPR sprout::tuples::tuple< inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::darkroom::materials::uniform_element<Color>, sprout::darkroom::materials::uniform_element<Color>,
sprout::darkroom::materials::uniform_element<Reflection> 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( return sprout::tuples::make_tuple(
sprout::darkroom::materials::make_uniform(col), sprout::darkroom::materials::make_uniform(col),
sprout::darkroom::materials::make_uniform(ref) sprout::darkroom::materials::make_uniform(ref)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -61,11 +61,7 @@ namespace sprout {
pixels_type pixels_; pixels_type pixels_;
public: public:
template<typename... Elems> template<typename... Elems>
SPROUT_CONSTEXPR image_type( SPROUT_CONSTEXPR image_type(unsigned long image_format, unsigned long pixel_format, Elems const&... elems)
unsigned long image_format,
unsigned long pixel_format,
Elems const&... elems
)
: pixels_{{ : pixels_{{
color_type( color_type(
static_cast<color_component_type>((elems >> 16) & 0xFF) / 0xFF, 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"); 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]; return pixels_[y * static_width + x];
} }
SPROUT_CONSTEXPR size_type width() const { SPROUT_CONSTEXPR size_type
width() const {
return static_width; return static_width;
} }
SPROUT_CONSTEXPR size_type height() const { SPROUT_CONSTEXPR size_type
height() const {
return static_height; return static_height;
} }
SPROUT_CONSTEXPR pixels_type const& pixels() const { SPROUT_CONSTEXPR pixels_type const&
pixels() const {
return pixels_; return pixels_;
} }
}; };

View file

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

View file

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

View file

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

View file

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

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