9
3

concepts.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Copyright 2019 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.hpp>
  16. #include <boost/concept_check.hpp>
  17. #include <boost/mp11.hpp>
  18. #include "test_fixture.hpp"
  19. namespace gil = boost::gil;
  20. namespace mp11 = boost::mp11;
  21. using boost::function_requires;
  22. template <template<typename> class Concept>
  23. struct assert_concept
  24. {
  25. template <typename Pixel>
  26. void operator()(Pixel&&)
  27. {
  28. function_requires<Concept<Pixel>>();
  29. }
  30. };
  31. template <template<typename> class Concept, typename... Pixels>
  32. void test_concept()
  33. {
  34. mp11::mp_for_each<Pixels...>(assert_concept<Concept>());
  35. }
  36. int main()
  37. {
  38. test_concept<gil::PixelConcept, gil::test::fixture::pixel_typedefs>();
  39. test_concept<gil::MutablePixelConcept, gil::test::fixture::pixel_typedefs>();
  40. using rgb565_pixel_t = gil::packed_pixel_type
  41. <
  42. std::uint16_t,
  43. mp11::mp_list_c<unsigned, 5, 6, 5>,
  44. gil::rgb_layout_t
  45. >::type;
  46. function_requires<gil::PixelConcept<rgb565_pixel_t>>();
  47. function_requires<gil::PixelValueConcept<rgb565_pixel_t>>();
  48. using bgr556_pixel_t = gil::packed_pixel_type
  49. <
  50. std::uint16_t,
  51. mp11::mp_list_c<unsigned, 5, 6, 5>,
  52. gil::bgr_layout_t>::type;
  53. function_requires<gil::PixelConcept<bgr556_pixel_t>>();
  54. function_requires<gil::PixelValueConcept<bgr556_pixel_t>>();
  55. function_requires<gil::PixelsCompatibleConcept<rgb565_pixel_t, bgr556_pixel_t>>();
  56. return 0;
  57. }