// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2014-2015 Oracle and/or its affiliates. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP #define BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP #include // define a custom number type and its sqrt in own namespace namespace number_types { template struct custom { typedef custom self; T m_value; custom() : m_value(0) {} explicit custom(T const& value) : m_value(value) {} bool operator<(self const& other) const { return m_value < other.m_value; } self operator-() const { return self(-m_value); } self operator-(self const& other) const { return self(m_value - other.m_value); } }; template inline custom sqrt(custom const& c) { return custom(std::sqrt(c.m_value)); } template inline custom fabs(custom const& c) { return custom(c.m_value < T(0) ? c.m_value : -c.m_value); } } // namespace number_types // define a custom number type with sqrt in global namespace namespace number_types { template struct custom_with_global_sqrt { typedef custom_with_global_sqrt self; T m_value; custom_with_global_sqrt() : m_value(0) {} explicit custom_with_global_sqrt(T const& value) : m_value(value) {} bool operator<(self const& other) const { return m_value < other.m_value; } self operator-() const { return self(-m_value); } self operator-(self const& other) const { return self(m_value - other.m_value); } }; } // namespace number_types template inline number_types::custom_with_global_sqrt sqrt(number_types::custom_with_global_sqrt const& c) { return number_types::custom_with_global_sqrt(std::sqrt(c.m_value)); } template inline number_types::custom_with_global_sqrt fabs(number_types::custom_with_global_sqrt const& c) { return number_types::custom_with_global_sqrt (c.m_value < T(0) ? c.m_value : -c.m_value); } // define a custom number type and its sqrt in global namespace template struct custom_global { typedef custom_global self; T m_value; custom_global() : m_value(0) {} explicit custom_global(T const& value) : m_value(value) {} bool operator<(self const& other) const { return m_value < other.m_value; } self operator-() const { return self(-m_value); } self operator-(self const& other) const { return self(m_value - other.m_value); } }; template inline custom_global sqrt(custom_global const& c) { return custom_global(std::sqrt(c.m_value)); } template inline custom_global fabs(custom_global const& c) { return custom_global(c.m_value < T(0) ? c.m_value : -c.m_value); } // custom number type without functions definition template struct custom_raw { typedef custom_raw self; T m_value; custom_raw() : m_value(0) {} explicit custom_raw(T const& value) : m_value(value) {} bool operator<(self const& other) const { return m_value < other.m_value; } self operator-() const { return self(-m_value); } self operator-(self const& other) const { return self(m_value - other.m_value); } }; #endif // BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP