is_final.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright 2016-2017 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/poly_collection for library home page.
  7. */
  8. #ifndef BOOST_POLY_COLLECTION_DETAIL_IS_FINAL_HPP
  9. #define BOOST_POLY_COLLECTION_DETAIL_IS_FINAL_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/type_traits/is_final.hpp>
  14. #include <type_traits>
  15. /* technique explained at
  16. * http://bannalia.blogspot.com/2016/09/compile-time-checking-existence-of.html
  17. */
  18. namespace boost{
  19. namespace poly_collection{
  20. namespace detail{
  21. namespace is_final_fallback{
  22. template<typename T> using is_final=boost::is_final<T>;
  23. struct hook{};
  24. }}}}
  25. namespace std{
  26. template<>
  27. struct is_void< ::boost::poly_collection::detail::is_final_fallback::hook>:
  28. std::false_type
  29. {
  30. template<typename T>
  31. static constexpr bool is_final_f()
  32. {
  33. using namespace ::boost::poly_collection::detail::is_final_fallback;
  34. return is_final<T>::value;
  35. }
  36. };
  37. } /* namespace std */
  38. namespace boost{
  39. namespace poly_collection{
  40. namespace detail{
  41. template<typename T>
  42. struct is_final:std::integral_constant<
  43. bool,
  44. std::is_void<is_final_fallback::hook>::template is_final_f<T>()
  45. >{};
  46. } /* namespace poly_collection::detail */
  47. } /* namespace poly_collection */
  48. } /* namespace boost */
  49. #endif