1
0

xfunctional.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /***************************************************************************
  2. * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
  3. * Copyright (c) QuantStack *
  4. * *
  5. * Distributed under the terms of the BSD 3-Clause License. *
  6. * *
  7. * The full license is in the file LICENSE, distributed with this software. *
  8. ****************************************************************************/
  9. #ifndef XTL_FUNCTIONAL_HPP
  10. #define XTL_FUNCTIONAL_HPP
  11. #include <utility>
  12. #include "xtl_config.hpp"
  13. #include "xtype_traits.hpp"
  14. namespace xtl
  15. {
  16. /***************************
  17. * identity implementation *
  18. ***************************/
  19. struct identity
  20. {
  21. template <class T>
  22. T&& operator()(T&& x) const
  23. {
  24. return std::forward<T>(x);
  25. }
  26. };
  27. /*************************
  28. * select implementation *
  29. *************************/
  30. template <class B, class T1, class T2, XTL_REQUIRES(all_scalar<B, T1, T2>)>
  31. inline std::common_type_t<T1, T2> select(const B& cond, const T1& v1, const T2& v2) noexcept
  32. {
  33. return cond ? v1 : v2;
  34. }
  35. }
  36. #endif