unit_element.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2008-2010: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_TYPE_TRAITS_UNIT_ELEMENT_HPP_JOFA_080912
  9. #define BOOST_ICL_TYPE_TRAITS_UNIT_ELEMENT_HPP_JOFA_080912
  10. #include <string>
  11. #include <boost/icl/type_traits/identity_element.hpp>
  12. #include <boost/icl/type_traits/succ_pred.hpp>
  13. namespace boost{ namespace icl
  14. {
  15. template <class Type> struct unit_element{ static Type value(); };
  16. template<> inline bool unit_element<bool>::value() { return true;}
  17. template<> inline float unit_element<float>::value() { return 1.0; }
  18. template<> inline double unit_element<double>::value() { return 1.0; }
  19. template<> inline long double unit_element<long double>::value()
  20. { return 1.0; }
  21. // Smallest 'visible' string that is greater than the empty string.
  22. template <>
  23. inline std::string unit_element<std::string>::value()
  24. { return std::string(" "); }
  25. template <class Type>
  26. inline Type unit_element<Type>::value()
  27. { return icl::succ(identity_element<Type>::value()); }
  28. }} // namespace boost icl
  29. #endif