1 // 2 // Copyright 2005-2007 Adobe Systems Incorporated 3 // Copyright 2018-2020 Mateusz Loskot <mateusz at loskot dot net> 4 // 5 // Distributed under the Boost Software License, Version 1.0 6 // See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt 8 // 9 #include <boost/gil/concepts.hpp> 10 11 #include <boost/core/lightweight_test.hpp> 12 13 #include <cstdint> 14 15 #include "test_fixture.hpp" 16 17 namespace gil = boost::gil; 18 namespace fixture = boost::gil::test::fixture; 19 20 // A channel archetype - to test the minimum requirements of the concept 21 struct channel_value_archetype; 22 23 struct channel_archetype 24 { 25 // equality comparable operator ==(channel_archetype const &,channel_archetype const &)26 friend bool operator==(channel_archetype const&, channel_archetype const&) 27 { return true; } 28 // inequality comparable operator !=(channel_archetype const &,channel_archetype const &)29 friend bool operator!=(channel_archetype const&, channel_archetype const&) 30 { return false; } 31 // less-than comparable operator <(channel_archetype const &,channel_archetype const &)32 friend bool operator<(channel_archetype const&, channel_archetype const&) 33 { return false; } 34 // convertible to a scalar operator std::uint8_tchannel_archetype35 operator std::uint8_t() const { return 0; } 36 operator ++channel_archetype37 channel_archetype& operator++() { return *this; } operator --channel_archetype38 channel_archetype& operator--() { return *this; } operator ++channel_archetype39 channel_archetype operator++(int) { return *this; } operator --channel_archetype40 channel_archetype operator--(int) { return *this; } 41 42 template <typename Scalar> operator +=channel_archetype43 channel_archetype operator+=(Scalar) { return *this; } 44 template <typename Scalar> operator -=channel_archetype45 channel_archetype operator-=(Scalar) { return *this; } 46 template <typename Scalar> operator *=channel_archetype47 channel_archetype operator*=(Scalar) { return *this; } 48 template <typename Scalar> operator /=channel_archetype49 channel_archetype operator/=(Scalar) { return *this; } 50 51 using value_type = channel_value_archetype; 52 using reference = channel_archetype; 53 using const_reference = channel_archetype const; 54 using pointer = channel_value_archetype*; 55 using const_pointer = channel_value_archetype const*; 56 static constexpr bool is_mutable = true; 57 58 static value_type min_value(); 59 static value_type max_value(); 60 }; 61 62 struct channel_value_archetype : public channel_archetype 63 { 64 // default constructible channel_value_archetypechannel_value_archetype65 channel_value_archetype() {} 66 // copy constructible 67 channel_value_archetype(channel_value_archetype const&) = default; 68 // assignable operator =channel_value_archetype69 channel_value_archetype& operator=(channel_value_archetype const&) 70 {return *this;} channel_value_archetypechannel_value_archetype71 channel_value_archetype(std::uint8_t) {} 72 }; 73 min_value()74channel_value_archetype channel_archetype::min_value() 75 { 76 return channel_value_archetype(); 77 } 78 max_value()79channel_value_archetype channel_archetype::max_value() 80 { 81 return channel_value_archetype(); 82 } 83 test_channel_minimal_requirements()84void test_channel_minimal_requirements() 85 { 86 // Do only compile-time tests for the archetype 87 // (because asserts like val1<val2 fail) 88 boost::function_requires<gil::MutableChannelConcept<channel_archetype>>(); 89 90 fixture::channel_value<channel_value_archetype>(); 91 fixture::channel_reference<channel_archetype>(); 92 fixture::channel_reference<channel_archetype const&>(); 93 } 94 main()95int main() 96 { 97 test_channel_minimal_requirements(); 98 99 return ::boost::report_errors(); 100 } 101