concepts.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // FIXME: Avoid Clang's flooding of non-disableable warnings like:
  9. // "T does not declare any constructor to initialize its non-modifiable members"
  10. // when compiling with concepts check enabled.
  11. // See https://bugs.llvm.org/show_bug.cgi?id=41759
  12. #if !defined(BOOST_GIL_USE_CONCEPT_CHECK) && !defined(__clang__)
  13. #error Compile with BOOST_GIL_USE_CONCEPT_CHECK defined
  14. #endif
  15. #include <boost/gil/concepts.hpp>
  16. #include <boost/gil/point.hpp>
  17. #include <type_traits>
  18. namespace gil = boost::gil;
  19. template <typename Point>
  20. void test_members()
  21. {
  22. static_assert(Point::num_dimensions == 2U, "point is not 2D");
  23. using value_t = typename Point::value_type;
  24. using coord_t = typename Point::template axis<0>::coord_t;
  25. static_assert(std::is_same<value_t, coord_t>::value,
  26. "point and axis type mismatch");
  27. }
  28. int main()
  29. {
  30. boost::function_requires<gil::PointNDConcept<gil::point<int>>>();
  31. boost::function_requires<gil::PointNDConcept<gil::point_t>>();
  32. boost::function_requires<gil::Point2DConcept<gil::point<int>>>();
  33. boost::function_requires<gil::Point2DConcept<gil::point_t>>();
  34. test_members<gil::point<int>>();
  35. test_members<gil::point_t>();
  36. // NOTE: point2 is deprecated, available for backward compatibility
  37. boost::function_requires<gil::PointNDConcept<gil::point2<int>>>();
  38. boost::function_requires<gil::Point2DConcept<gil::point2<int>>>();
  39. test_members<gil::point2<int>>();
  40. return 0;
  41. }