Skip to content

Commit

Permalink
Merge branch 'master' into sound_c_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yumetodo committed Feb 26, 2016
2 parents 8bedec5 + 268565f commit 8d14f03
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 75 deletions.
2 changes: 1 addition & 1 deletion ProjectDxLibEx.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ClInclude Include="dxlibex\algorithm\cast_if.hpp" />
<ClInclude Include="dxlibex\algorithm\safe_dist.hpp" />
<ClInclude Include="dxlibex\basic_types.hpp" />
<ClInclude Include="dxlibex\basic_types\arithmetic_t.hpp" />
<ClInclude Include="dxlibex\basic_types\use_big_type_when_one_byte_t.hpp" />
<ClInclude Include="dxlibex\basic_types\coordinate_operator_bool_helper.hpp" />
<ClInclude Include="dxlibex\basic_types\distance_result_type_t.hpp" />
<ClInclude Include="dxlibex\basic_types\point2d.hpp" />
Expand Down
2 changes: 1 addition & 1 deletion ProjectDxLibEx.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<ClInclude Include="dxlibex\Color.hpp">
<Filter>dxlibex</Filter>
</ClInclude>
<ClInclude Include="dxlibex\basic_types\arithmetic_t.hpp">
<ClInclude Include="dxlibex\basic_types\use_big_type_when_one_byte_t.hpp">
<Filter>dxlibex\basic_types</Filter>
</ClInclude>
<ClInclude Include="dxlibex\basic_types\point2d.hpp">
Expand Down
36 changes: 18 additions & 18 deletions dxlibex/basic_types/point2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "dxlibex/type_traits/is_representable.hpp"
#include "dxlibex/type_traits/is_nothrow.hpp"
#include "dxlibex/type_traits/ignore.hpp"
#include "dxlibex/basic_types/arithmetic_t.hpp"
#include "dxlibex/basic_types/use_big_type_when_one_byte_t.hpp"
#include "dxlibex/basic_types/stdint.hpp"
#include "dxlibex/basic_types/distance_result_type_t.hpp"
#include "dxlibex/basic_types/coordinate_operator_bool_helper.hpp"
Expand All @@ -32,7 +32,7 @@
#include "dxlibex/config/defines.h"

namespace dxle {
template<typename T, enable_if_t<std::is_arithmetic<T>::value && std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value, nullptr_t>>
template<typename T, enable_if_t<std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value, nullptr_t>>
class size_c;
/**
\~japanese @brief 2次元座標(x, y) テンプレートクラス。
Expand Down Expand Up @@ -107,7 +107,7 @@ namespace dxle {
public:
typedef typename std::remove_cv<T>::type value_type;
value_type x, y;
DXLE_CONSTEXPR_CLASS point_c() DXLE_NOEXCEPT_IF(std::is_nothrow_constructible<value_type>::value) : x(), y() {}
DXLE_CONSTEXPR_CLASS point_c() DXLE_NOEXCEPT_IF((std::is_nothrow_constructible<value_type>::value)) : x(), y() {}
DXLE_CONSTEXPR_CLASS point_c(const value_type& x_, const value_type& y_) DXLE_NOEXCEPT_IF((std::is_nothrow_copy_constructible<value_type>::value)) : x(x_), y(y_) {}
DXLE_CONSTEXPR_CLASS point_c(value_type&& x_, value_type&& y_) DXLE_NOEXCEPT_OR_NOTHROW : x(std::move(x_)), y(std::move(y_)) {}

Expand Down Expand Up @@ -162,41 +162,41 @@ namespace dxle {
@relates point_c
\~japanese @brief std::pairからの変換
\~english @brief conversion from std::pair
\~japanese @param p std::pairオブジェクトへのconst-lvalue reference
\~english @param p const-lvalue reference to std::pair
\~japanese @param pa std::pairオブジェクトへのconst-lvalue reference
\~english @param pa const-lvalue reference to std::pair
\~japanese @return point_cクラスオブジェクト
\~english @return point_c value
*/
template<typename T> point_c<T> make_point_c(const std::pair<T, T>& p) DXLE_NOEXCEPT_IF(std::is_nothrow_copy_constructible<T>::value)
template<typename T> point_c<T> make_point_c(const std::pair<T, T>& pa) DXLE_NOEXCEPT_IF(std::is_nothrow_copy_constructible<T>::value)
{
return point_c<T>(p.first, p.second);
return point_c<T>(pa.first, pa.second);
}
/**
@relates point_c
\~japanese @brief std::pairからの変換
\~english @brief conversion from std::pair
\~japanese @param p std::pairオブジェクトへのrvalue reference
\~english @param p rvalue reference to std::pair
\~japanese @param pa std::pairオブジェクトへのrvalue reference
\~english @param pa rvalue reference to std::pair
\~japanese @return point_cクラスオブジェクト
\~english @return point_c value
*/
template<typename T> point_c<T> make_point_c(std::pair<T, T>&& p) DXLE_NOEXCEPT_OR_NOTHROW
template<typename T> point_c<T> make_point_c(std::pair<T, T>&& pa) DXLE_NOEXCEPT_OR_NOTHROW
{
return point_c<T>(std::move(p.first), std::move(p.second));
return point_c<T>(std::move(pa.first), std::move(pa.second));
}

//ostream operator
namespace detail {
template<typename CharType, typename PointType>
void ostream_operator_helper(std::basic_ostream<CharType>& os, const CharType* str, const point_c<PointType>& p)
{
using arithmetic_p = arithmetic_t<PointType>;
os << static_cast<arithmetic_p>(p.x) << str << static_cast<arithmetic_p>(p.y);
using use_big_type_when_one_byte_p = use_big_type_when_one_byte_t<PointType>;
os << static_cast<use_big_type_when_one_byte_p>(p.x) << str << static_cast<use_big_type_when_one_byte_p>(p.y);
}
template<typename CharType, typename PointType>
void istream_operator_helper(std::basic_istream<CharType>& is, point_c<PointType>& p)
{
arithmetic_t<PointType> x, y;
use_big_type_when_one_byte_t<PointType> x, y;
is >> x;
is.ignore((std::numeric_limits<std::streamsize>::max)(), ',');
is >> y;
Expand Down Expand Up @@ -232,7 +232,7 @@ namespace dxle {
*/
template<typename T> std::wostream& operator<<(std::wostream& os, const point_c<T>& p)
{
detail::ostream_operator_helper<wchar_t, T>(os, L", ", p);
dxle::detail::ostream_operator_helper<wchar_t, T>(os, L", ", p);
return os;
}
/**
Expand Down Expand Up @@ -264,7 +264,7 @@ namespace dxle {
*/
template<typename T> std::wistream& operator>>(std::wistream& is, point_c<T>& p)
{
detail::istream_operator_helper<wchar_t, T>(is, p);
dxle::detail::istream_operator_helper<wchar_t, T>(is, s);
return is;
}

Expand Down Expand Up @@ -554,7 +554,7 @@ namespace dxle {
@endcode
*/
template <typename T>
DXLE_CONSTEXPR_CLASS bool operator ==(const point_c<T>& p, std::nullptr_t) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
DXLE_CONSTEXPR_CLASS bool operator ==(const point_c<T>& p, nullptr_t) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
{
return !static_cast<bool>(p);
}
Expand All @@ -572,7 +572,7 @@ namespace dxle {
@endcode
*/
template <typename T>
DXLE_CONSTEXPR_CLASS bool operator ==(std::nullptr_t, const point_c<T>& p) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
DXLE_CONSTEXPR_CLASS bool operator ==(nullptr_t, const point_c<T>& p) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
{
return !static_cast<bool>(p);
}
Expand Down
71 changes: 47 additions & 24 deletions dxlibex/basic_types/point3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "dxlibex/type_traits/first_enabled.hpp"
#include "dxlibex/type_traits/enable_if.hpp"
#include "dxlibex/type_traits/is_representable.hpp"
#include "dxlibex/basic_types/arithmetic_t.hpp"
#include "dxlibex/basic_types/use_big_type_when_one_byte_t.hpp"
#include "dxlibex/basic_types/stdint.hpp"
#include "dxlibex/basic_types/distance_result_type_t.hpp"
#include "dxlibex/basic_types/coordinate_operator_bool_helper.hpp"
Expand Down Expand Up @@ -68,8 +68,32 @@ namespace dxle {
dxle::point3di pt = (a + b)*10.f;
std::cout << pt << std::endl;
@endcode
\~english @tparam T
\~english T is the type of the elements. T must meet the requirements of <a href="http://en.cppreference.com/w/cpp/types/is_move_assignable">NothrowMoveAssignable</a> and <a href="http://en.cppreference.com/w/cpp/types/is_move_constructible">NothrowConstructable</a>.
\~english T is expected the following conditions to use all features.
\~english - <a href="http://en.cppreference.com/w/cpp/concept/DefaultConstructible">DefaultConstructible</a>
\~english - <a href="http://en.cppreference.com/w/cpp/concept/CopyConstructible">CopyConstructible</a>
\~english - <a href="http://en.cppreference.com/w/cpp/concept/CopyAssignable">CopyAssignable</a>
\~english - has unary operator + -
\~english - has binary operator + - * / += -= *= /= == !=
\~english - has binary operator != to compare with 0
\~english - able to call functon abs and hypot.
\~english - <a href="http://en.cppreference.com/w/cpp/types/is_floating_point">std::is_floating_point</a><T> == true or able to convert to double via static_cast.
\~japanese @tparam T
\~japanese 型Tは少なくとも以下の条件を満たしている必要があります。
\~japanese - 型が例外を投げずにムーブ構築可能であること(<a href="http://cpprefjp.github.io/reference/type_traits/is_nothrow_move_constructible.html">is_nothrow_move_constructible</a><T>::value == trueであること)
\~japanese - 型が例外を投げずにムーブ代入可能であること(<a href="http://cpprefjp.github.io/reference/type_traits/is_nothrow_move_assignable.html">is_nothrow_move_assignable</a><T>::value == trueであること)
\~japanese .
\~japanese また、以下の条件を満たしている事が期待されています。
\~japanese - 型がデフォルト構築可能であること(<a href="http://cpprefjp.github.io/reference/type_traits/is_default_constructible.html">is_default_constructible</a><T>::value == trueであること)
\~japanese - 型がコピー構築可能であること(<a href="http://cpprefjp.github.io/reference/type_traits/is_copy_constructible.html">is_copy_constructible</a><T>::value == trueであること)
\~japanese - 型がコピー代入可能であること(<a href="http://cpprefjp.github.io/reference/type_traits/is_copy_assignable.html">is_copy_assignable</a><T>::value == trueであること)
\~japanese - 単項 + - 演算子を持つこと
\~japanese - 二項 + - * / += -= *= /= == != 演算子を持つこと
\~japanese - 0と!=で比較することが可能であること( t != 0; (tはconst T&型の変数)がコンパイル可能であること)
\~japanese - abs, hypot関数がADLなどで見つかること
*/
template<typename T, enable_if_t<std::is_arithmetic<T>::value && std::is_move_constructible<T>::value, nullptr_t> = nullptr>
template<typename T, enable_if_t<std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value, nullptr_t> = nullptr>
class point3d_c final
{
public:
Expand All @@ -80,11 +104,11 @@ namespace dxle {
DXLE_CONSTEXPR_CLASS point3d_c(value_type&& x_, value_type&& y_, value_type&& z_) DXLE_NOEXCEPT_OR_NOTHROW : x(std::move(x_)), y(std::move(y_)), z(std::move(z_)) {}

//copy constructor
DXLE_CONSTEXPR_CLASS point3d_c(const point3d_c<value_type>& o) DXLE_NOEXCEPT_IF(std::is_nothrow_copy_constructible<value_type>::value) : x(o.x), y(o.y), z(o.z) {}
DXLE_CONSTEXPR_CLASS point3d_c(const point3d_c<value_type>& o) DXLE_NOEXCEPT_IF((std::is_nothrow_copy_constructible<value_type>::value)) : x(o.x), y(o.y), z(o.z) {}
//move constructor
DXLE_CONSTEXPR_CLASS point3d_c(point3d_c<value_type>&& o) DXLE_NOEXCEPT_OR_NOTHROW : x(std::move(o.x)), y(std::move(o.y)), z(std::move(o.z)) {}
//copy assignment operator
point3d_c& operator=(const point3d_c<value_type>& r) DXLE_NOEXCEPT_IF(std::is_nothrow_copy_assignable<value_type>::value)
point3d_c& operator=(const point3d_c<value_type>& r) DXLE_NOEXCEPT_IF((std::is_nothrow_copy_assignable<value_type>::value))
{
this->x = r.x;
this->y = r.y;
Expand All @@ -99,7 +123,6 @@ namespace dxle {
this->z = std::move(r.z);
return *this;
}

//!operator bool
//!1. operator bool
//!2. operator != (nullptr)
Expand Down Expand Up @@ -154,13 +177,13 @@ namespace dxle {
template<typename CharType, typename point3dType>
void ostream_operator_helper(std::basic_ostream<CharType>& os, const CharType* str, const point3d_c<point3dType>& p)
{
using arithmetic_p = arithmetic_t<point3dType>;
os << static_cast<arithmetic_p>(p.x) << str << static_cast<arithmetic_p>(p.y) << str << static_cast<arithmetic_p>(p.z);
using use_big_type_when_one_byte_p = use_big_type_when_one_byte_t<point3dType>;
os << static_cast<use_big_type_when_one_byte_p>(p.x) << str << static_cast<use_big_type_when_one_byte_p>(p.y) << str << static_cast<use_big_type_when_one_byte_p>(p.z);
}
template<typename CharType, typename point3dType>
void istream_operator_helper(std::basic_istream<CharType>& is, point3d_c<point3dType>& p)
{
arithmetic_t<point3dType> x, y, z;
use_big_type_when_one_byte_t<point3dType> x, y, z;
is >> x;
is.ignore((std::numeric_limits<std::streamsize>::max)(), ',');
is >> y;
Expand Down Expand Up @@ -360,7 +383,7 @@ namespace dxle {
\~japanese @return point3d_cクラスオブジェクトの各メンバーに第二引数を乗じた結果
\~english @return Memberwise multiplication by 2nd argument
*/
template <typename T1, typename T2, enable_if_t<std::is_arithmetic<T2>::value, nullptr_t> = nullptr>
template <typename T1, typename T2>
DXLE_CONSTEXPR_CLASS auto operator *(const point3d_c<T1>& l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x * r)
->point3d_c<decltype(std::declval<std::remove_cv_t<T1>>() * std::declval<std::remove_cv_t<T2>>())>
{
Expand All @@ -378,7 +401,7 @@ namespace dxle {
\~japanese @return point3d_cクラスオブジェクトの各メンバーに第一引数を乗じた結果
\~english @return Memberwise multiplication by 1st argument
*/
template <typename T1, typename T2, enable_if_t<std::is_arithmetic<T1>::value, nullptr_t> = nullptr>
template <typename T1, typename T2>
DXLE_CONSTEXPR_CLASS auto operator *(T1 l, const point3d_c<T2>& r) DXLE_NOEXCEPT_IF_EXPR(l + r.x)
->point3d_c<decltype(std::declval<std::remove_cv_t<T1>>() * std::declval<std::remove_cv_t<T2>>())>
{
Expand All @@ -396,7 +419,7 @@ namespace dxle {
\~japanese @return 第一引数へのlvalue reference
\~english @return lvalue reference to 1st argument
*/
template <typename T1, typename T2, enable_if_t<std::is_arithmetic<T2>::value && is_representable<T2, T1>::value, nullptr_t> = nullptr>
template <typename T1, typename T2, enable_if_t<is_representable<T2, T1>::value, nullptr_t> = nullptr>
point3d_c<T1>& operator *=(point3d_c<T1>& l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x *= r)
{
l.x *= r;
Expand All @@ -416,7 +439,7 @@ namespace dxle {
\~japanese @return point3d_cクラスオブジェクトの各メンバーを第一引数で割った結果
\~english @return Memberwise multiplication by 1st argument
*/
template <typename T1, typename T2, enable_if_t<std::is_arithmetic<T2>::value, nullptr_t> = nullptr>
template <typename T1, typename T2>
DXLE_CONSTEXPR_CLASS auto operator /(const point3d_c<T1>& l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x / r)
->point3d_c<decltype(std::declval<std::remove_cv_t<T1>>() - std::declval<std::remove_cv_t<T2>>())>
{
Expand All @@ -434,7 +457,7 @@ namespace dxle {
\~japanese @return 第一引数へのlvalue reference
\~english @return lvalue reference to 1st argument
*/
template <typename T1, typename T2, enable_if_t<std::is_arithmetic<T2>::value && is_representable<T2, T1>::value, nullptr_t> = nullptr>
template <typename T1, typename T2, enable_if_t<is_representable<T2, T1>::value, nullptr_t> = nullptr>
point3d_c<T1>& operator /=(point3d_c<T1>& l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x /= r)
{
l.x /= r;
Expand All @@ -454,7 +477,7 @@ namespace dxle {
\~japanese @return 左辺と右辺が等しくなければtrueを返す
\~english @return true if left operand is not equal to right operand
*/
template <typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
template <typename T>
DXLE_CONSTEXPR_CLASS bool operator !=(const point3d_c<T>& l, const point3d_c<T>& r) DXLE_NOEXCEPT_IF_EXPR(l.x != r.x)
{
return (l.x != r.x) || (l.y != r.y) || (l.z != r.z);
Expand All @@ -473,7 +496,7 @@ namespace dxle {
bool re = p != 0;//false
@endcode
*/
template <typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
template <typename T>
DXLE_CONSTEXPR_CLASS bool operator !=(const point3d_c<T>& p, nullptr_t) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
{
return !static_cast<bool>(p);
Expand All @@ -492,7 +515,7 @@ namespace dxle {
bool re = 0 != p;//false
@endcode
*/
template <typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
template <typename T>
DXLE_CONSTEXPR_CLASS bool operator !=(nullptr_t, const point3d_c<T>& p) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
{
return !static_cast<bool>(p);
Expand Down Expand Up @@ -525,10 +548,10 @@ namespace dxle {
bool re = 0 == p;//true
@endcode
*/
template <typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
template <typename T>
DXLE_CONSTEXPR_CLASS bool operator ==(const point3d_c<T>& p, nullptr_t) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
{
return static_cast<bool>(p);
return !static_cast<bool>(p);
}

/**
Expand All @@ -544,7 +567,7 @@ namespace dxle {
bool re = 0 == p;//true
@endcode
*/
template <typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
template <typename T>
DXLE_CONSTEXPR_CLASS bool operator ==(nullptr_t, const point3d_c<T>& p) DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(p))
{
return static_cast<bool>(p);
Expand All @@ -563,7 +586,7 @@ namespace dxle {
const auto result = dxle::abs(p1);//(2, 4)
@endcode
*/
template<typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
template<typename T>
DXLE_CONSTEXPR_CLASS point3d_c<T> abs(const point3d_c<T>& o) DXLE_NOEXCEPT_IF_EXPR(abs(o.x)) { return{ abs(o.x), abs(o.y), abs(o.z) }; }

/**
Expand All @@ -577,7 +600,7 @@ namespace dxle {
\~japanese @return 計算結果。戻り値の型は暗黙の型変換で得られるものです。
\~english @return Computed result. return value's type is a result of Implicit conversions.
*/
template<typename T1, typename T2, enable_if_t<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value, nullptr_t> = nullptr>
template<typename T1, typename T2>
DXLE_CONSTEXPR_CLASS auto dot(const point3d_c<T1>& p1, const point3d_c<T2>& p2) DXLE_NOEXCEPT_IF_EXPR(p1.x * p2.x + p1.y * p2.y + p1.z * p2.z)
-> decltype(std::declval<std::remove_cv_t<T1>>() * std::declval<std::remove_cv_t<T2>>())
{
Expand All @@ -595,7 +618,7 @@ namespace dxle {
\~japanese @return 計算結果。
\~english @return Computed result.
*/
template<typename T1, typename T2, enable_if_t<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value, nullptr_t> = nullptr>
template<typename T1, typename T2>
DXLE_CONSTEXPR_CLASS auto cross(const point3d_c<T1>& p1, const point3d_c<T2>& p2) DXLE_NOEXCEPT_IF_EXPR(std::declval<T1>() * std::declval<T2>() - std::declval<T1>() * std::declval<T2>())
->point3d_c<decltype(std::declval<std::remove_cv_t<T1>>() * std::declval<std::remove_cv_t<T2>>())>
{
Expand All @@ -616,9 +639,9 @@ namespace dxle {
*/
template<typename T1, typename T2>
distance_result_type_t<T1, T2> distance(const point3d_c<T1>& p1, const point3d_c<T2>& p2)
DXLE_NOEXCEPT_IF_EXPR(std::hypot(safe_dist(std::declval<T1>(), std::declval<T2>()), safe_dist(std::declval<T1>(), std::declval<T2>())))
DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std::declval<T1>(), std::declval<T2>()), safe_dist(std::declval<T1>(), std::declval<T2>())))
{
return std::hypot(safe_dist(p1.x, p2.x), std::hypot(safe_dist(p1.y, p2.y), safe_dist(p1.z, p2.z)));
return hypot(safe_dist(p1.x, p2.x), (safe_dist(p1.y, p2.y), safe_dist(p1.z, p2.z)));
}
typedef point3d_c<int> point3di;
typedef point3d_c<std::uint8_t> point3du8i;
Expand Down
Loading

0 comments on commit 8d14f03

Please sign in to comment.