Skip to content

Commit

Permalink
Remove dependency on Boost.StaticAssert
Browse files Browse the repository at this point in the history
Replaced BOOST_STATIC_ASSERT with C++11 binary static_assert,
with empty message.

In future, this should make it possible to automatically refactor
into C++17 unary static_assert using clang-tidy and
its modernize-unary-static-assert check.

Closes #106
  • Loading branch information
mloskot committed Jan 10, 2019
1 parent 7722f08 commit 68fe3db
Show file tree
Hide file tree
Showing 38 changed files with 177 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ before_build:
- git submodule --quiet update --init libs/numeric/conversion
- git submodule --quiet update --init libs/preprocessor
- git submodule --quiet update --init libs/smart_ptr
- git submodule --quiet update --init libs/static_assert
- git submodule --quiet update --init libs/test
- git submodule --quiet update --init libs/type_traits
## Transitive
Expand All @@ -120,6 +119,7 @@ before_build:
- git submodule --quiet update --init libs/ratio
- git submodule --quiet update --init libs/rational
- git submodule --quiet update --init libs/regex
- git submodule --quiet update --init libs/static_assert
- git submodule --quiet update --init libs/system
- git submodule --quiet update --init libs/throw_exception
- git submodule --quiet update --init libs/timer
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ install:
- git submodule --quiet update --init libs/mpl
- git submodule --quiet update --init libs/numeric/conversion
- git submodule --quiet update --init libs/preprocessor
- git submodule --quiet update --init libs/static_assert
- git submodule --quiet update --init libs/test
- git submodule --quiet update --init libs/type_traits
## Transitive
Expand All @@ -237,6 +236,7 @@ install:
- git submodule --quiet update --init libs/ratio
- git submodule --quiet update --init libs/rational
- git submodule --quiet update --init libs/regex
- git submodule --quiet update --init libs/static_assert
- git submodule --quiet update --init libs/smart_ptr
- git submodule --quiet update --init libs/system
- git submodule --quiet update --init libs/throw_exception
Expand Down
12 changes: 6 additions & 6 deletions doc/design_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ provides a model for such packed pixel formats::
typedef packed_pixel_type<uint16_t, mpl::vector3_c<unsigned,5,6,5>, rgb_layout_t>::type rgb565_pixel_t;

function_requires<PixelValueConcept<rgb565_pixel_t> >();
BOOST_STATIC_ASSERT((sizeof(rgb565_pixel_t)==2));
static_assert(sizeof(rgb565_pixel_t) == 2, "");

// define a bgr556 pixel
typedef packed_pixel_type<uint16_t, mpl::vector3_c<unsigned,5,6,5>, bgr_layout_t>::type bgr556_pixel_t;
Expand Down Expand Up @@ -838,7 +838,7 @@ pixels and pixel iterators::

// BGR232 pixel value. It is a packed_pixel of size 1 byte. (The last bit is unused)
typedef std::iterator_traits<bgr232_ptr_t>::value_type bgr232_pixel_t;
BOOST_STATIC_ASSERT((sizeof(bgr232_pixel_t)==1));
static_assert(sizeof(bgr232_pixel_t) == 1, "");

bgr232_pixel_t red(0,0,3); // = 0RRGGGBB, = 01100000 = 0x60

Expand Down Expand Up @@ -1959,7 +1959,7 @@ an example::
#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
using namespace boost;

#define ASSERT_SAME(A,B) BOOST_STATIC_ASSERT((is_same< A,B >::value))
#define ASSERT_SAME(A,B) static_assert(is_same< A,B >::value, "")

// Define the set of allowed images
typedef mpl::vector<rgb8_image_t, cmyk16_planar_image_t> my_images_t;
Expand Down Expand Up @@ -2380,7 +2380,7 @@ HomogeneousPixelBasedConcept and metafunctions built on top of them::
These are metafunctions, some of which return integral types which can
be evaluated like this::

BOOST_STATIC_ASSERT(is_planar<rgb8_planar_view_t>::value == true);
static_assert(is_planar<rgb8_planar_view_t>::value == true, "");

GIL also supports type analysis metafunctions of the form:
[pixel_reference/iterator/locator/view/image] + "_is_" +
Expand Down Expand Up @@ -2537,10 +2537,10 @@ Here is how to use pixels in generic code::
gil_function_requires<MutableHomogeneousPixelConcept<RGBPixel> >();

typedef typename color_space_type<GrayPixel>::type gray_cs_t;
BOOST_STATIC_ASSERT((boost::is_same<gray_cs_t,gray_t>::value));
static_assert(boost::is_same<gray_cs_t,gray_t>::value, "");

typedef typename color_space_type<RGBPixel>::type rgb_cs_t;
BOOST_STATIC_ASSERT((boost::is_same<rgb_cs_t,rgb_t>::value));
static_assert(boost::is_same<rgb_cs_t,rgb_t>::value, "");

typedef typename channel_type<GrayPixel>::type gray_channel_t;
typedef typename channel_type<RGBPixel>::type rgb_channel_t;
Expand Down
12 changes: 6 additions & 6 deletions doc/doxygen/design_guide.dox
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ channels occupy bits [0..4],[5..9] and [10..15] respectively. GIL provides a mod
typedef packed_pixel_type<uint16_t, mpl::vector3_c<unsigned,5,6,5>, rgb_layout_t>::type rgb565_pixel_t;

function_requires<PixelValueConcept<rgb565_pixel_t> >();
BOOST_STATIC_ASSERT((sizeof(rgb565_pixel_t)==2));
static_assert(sizeof(rgb565_pixel_t) == 2, "");

// define a bgr556 pixel
typedef packed_pixel_type<uint16_t, mpl::vector3_c<unsigned,5,6,5>, bgr_layout_t>::type bgr556_pixel_t;
Expand All @@ -912,7 +912,7 @@ typedef bit_aligned_pixel_iterator<bgr232_ref_t> bgr232_ptr_t;

// BGR232 pixel value. It is a packed_pixel of size 1 byte. (The last bit is unused)
typedef std::iterator_traits<bgr232_ptr_t>::value_type bgr232_pixel_t;
BOOST_STATIC_ASSERT((sizeof(bgr232_pixel_t)==1));
static_assert(sizeof(bgr232_pixel_t) == 1, "");

bgr232_pixel_t red(0,0,3); // = 0RRGGGBB, = 01100000 = 0x60

Expand Down Expand Up @@ -1965,7 +1965,7 @@ depth. How can we possibly write this using our generic image? What type is the
#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
using namespace boost;

#define ASSERT_SAME(A,B) BOOST_STATIC_ASSERT((is_same< A,B >::value))
#define ASSERT_SAME(A,B) static_assert(is_same< A,B >::value, "")

// Define the set of allowed images
typedef mpl::vector<rgb8_image_t, cmyk16_planar_image_t> my_images_t;
Expand Down Expand Up @@ -2351,7 +2351,7 @@ template <typename T> struct num_channels { typedef ... type; };
These are metafunctions, some of which return integral types which can be evaluated like this:

\code
BOOST_STATIC_ASSERT(is_planar<rgb8_planar_view_t>::value == true);
static_assert(is_planar<rgb8_planar_view_t>::value == true, "");
\endcode

\endcode
Expand Down Expand Up @@ -2493,10 +2493,10 @@ void gray_to_rgb(const GrayPixel& src, RGBPixel& dst) {
gil_function_requires<MutableHomogeneousPixelConcept<RGBPixel> >();

typedef typename color_space_type<GrayPixel>::type gray_cs_t;
BOOST_STATIC_ASSERT((boost::is_same<gray_cs_t,gray_t>::value));
static_assert(boost::is_same<gray_cs_t,gray_t>::value, "");

typedef typename color_space_type<RGBPixel>::type rgb_cs_t;
BOOST_STATIC_ASSERT((boost::is_same<rgb_cs_t,rgb_t>::value));
static_assert(boost::is_same<rgb_cs_t,rgb_t>::value, "");

typedef typename channel_type<GrayPixel>::type gray_channel_t;
typedef typename channel_type<RGBPixel>::type rgb_channel_t;
Expand Down
12 changes: 9 additions & 3 deletions include/boost/gil/bit_aligned_pixel_reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ struct bit_aligned_pixel_reference {
template <bool IsMutable2> bit_aligned_pixel_reference(const bit_aligned_pixel_reference<BitField,ChannelBitSizes,Layout,IsMutable2>& p) : _bit_range(p._bit_range) {}

// Grayscale references can be constructed from the channel reference
explicit bit_aligned_pixel_reference(const typename kth_element_type<bit_aligned_pixel_reference,0>::type channel0) : _bit_range(static_cast<data_ptr_t>(&channel0), channel0.first_bit()) {
BOOST_STATIC_ASSERT((num_channels<bit_aligned_pixel_reference>::value==1));
explicit bit_aligned_pixel_reference(typename kth_element_type<bit_aligned_pixel_reference,0>::type const channel0)
: _bit_range(static_cast<data_ptr_t>(&channel0), channel0.first_bit())
{
static_assert(num_channels<bit_aligned_pixel_reference>::value == 1, "");
}

// Construct from another compatible pixel type
Expand Down Expand Up @@ -159,7 +161,11 @@ struct bit_aligned_pixel_reference {
template <typename Pixel> bool equal(const Pixel& p, mpl::true_) const { check_compatible<Pixel>(); return static_equal(*this,p); }

private:
static void check_gray() { BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
static void check_gray()
{
static_assert(is_same<typename Layout::color_space_t, gray_t>::value, "");
}

template <typename Channel> void assign(const Channel& chan, mpl::false_) const { check_gray(); gil::at_c<0>(*this)=chan; }
template <typename Channel> bool equal (const Channel& chan, mpl::false_) const { check_gray(); return gil::at_c<0>(*this)==chan; }
};
Expand Down
2 changes: 1 addition & 1 deletion include/boost/gil/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ using bits4 = packed_channel_value<4>;
assert(channel_traits<bits4>::min_value()==0);
assert(channel_traits<bits4>::max_value()==15);
assert(sizeof(bits4)==1);
BOOST_STATIC_ASSERT((boost::is_integral<bits4>::value));
static_assert(boost::is_integral<bits4>::value, "");
\endcode
*/

Expand Down
8 changes: 4 additions & 4 deletions include/boost/gil/color_base_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace boost { namespace gil {
Example:
\code
BOOST_STATIC_ASSERT((size<rgb8_pixel_t>::value == 3));
BOOST_STATIC_ASSERT((size<cmyk8_planar_ptr_t>::value == 4));
static_assert(size<rgb8_pixel_t>::value == 3, "");
static_assert(size<cmyk8_planar_ptr_t>::value == 4, "");
\endcode
*/

Expand Down Expand Up @@ -133,7 +133,7 @@ Example: A function that takes a generic pixel containing a red channel and sets
template <typename Pixel>
void set_red_to_max(Pixel& pixel) {
boost::function_requires<MutablePixelConcept<Pixel> >();
BOOST_STATIC_ASSERT((contains_color<Pixel, red_t>::value));
static_assert(contains_color<Pixel, red_t>::value, "");
using red_channel_t = typename color_element_type<Pixel, red_t>::type;
get_color(pixel, red_t()) = channel_traits<red_channel_t>::max_value();
Expand Down Expand Up @@ -192,7 +192,7 @@ typename color_element_const_reference_type<ColorBase,Color>::type get_color(con
Example:
\code
using element_t = element_type<rgb8c_planar_ptr_t>::type;
BOOST_STATIC_ASSERT((boost::is_same<element_t, const uint8_t*>::value));
static_assert(boost::is_same<element_t, const uint8_t*>::value, "");
\endcode
*/
/// \brief Specifies the element type of a homogeneous color base
Expand Down
2 changes: 1 addition & 1 deletion include/boost/gil/concepts/basic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct SameType
{
void constraints()
{
BOOST_STATIC_ASSERT((boost::is_same<T, U>::value_core));
static_assert(boost::is_same<T, U>::value_core, "");
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/boost/gil/concepts/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct ChannelValueConcept
/// Example:
///
/// \code
/// BOOST_STATIC_ASSERT((channels_are_compatible<uint8_t, const uint8_t&>::value));
/// static_assert(channels_are_compatible<uint8_t, const uint8_t&>::value, "");
/// \endcode
/// \ingroup ChannelAlgorithm
template <typename T1, typename T2> // Models GIL Pixel
Expand All @@ -167,7 +167,7 @@ struct ChannelsCompatibleConcept
{
void constraints()
{
BOOST_STATIC_ASSERT((channels_are_compatible<Channel1, Channel2>::value));
static_assert(channels_are_compatible<Channel1, Channel2>::value, "");
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/boost/gil/concepts/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct ColorSpacesCompatibleConcept
{
void constraints()
{
BOOST_STATIC_ASSERT((color_spaces_are_compatible<CS1, CS2>::value));
static_assert(color_spaces_are_compatible<CS1, CS2>::value, "");
}
};

Expand Down
6 changes: 3 additions & 3 deletions include/boost/gil/concepts/color_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct HomogeneousColorBaseConcept
using T0 = typename kth_element_type<ColorBase, 0>::type;
using TN = typename kth_element_type<ColorBase, num_elements - 1>::type;

BOOST_STATIC_ASSERT((is_same<T0, TN>::value)); // better than nothing
static_assert(is_same<T0, TN>::value, ""); // better than nothing

using R0 = typename kth_element_const_reference_type<ColorBase, 0>::type;
R0 r = dynamic_at_c(cb, 0);
Expand Down Expand Up @@ -296,11 +296,11 @@ struct ColorBasesCompatibleConcept
{
void constraints()
{
BOOST_STATIC_ASSERT((is_same
static_assert(is_same
<
typename ColorBase1::layout_t::color_space_t,
typename ColorBase2::layout_t::color_space_t
>::value));
>::value, "");

// using e1 = typename kth_semantic_element_type<ColorBase1,0>::type;
// using e2 = typename kth_semantic_element_type<ColorBase2,0>::type;
Expand Down
6 changes: 3 additions & 3 deletions include/boost/gil/concepts/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ struct ImageConcept
gil_function_requires<RandomAccess2DImageConcept<Image>>();
gil_function_requires<MutableImageViewConcept<typename Image::view_t>>();
using coord_t = typename Image::coord_t;
BOOST_STATIC_ASSERT(num_channels<Image>::value == mpl::size<typename color_space_type<Image>::type>::value);
static_assert(num_channels<Image>::value == mpl::size<typename color_space_type<Image>::type>::value, "");

BOOST_STATIC_ASSERT((is_same<coord_t, typename Image::x_coord_t>::value));
BOOST_STATIC_ASSERT((is_same<coord_t, typename Image::y_coord_t>::value));
static_assert(is_same<coord_t, typename Image::x_coord_t>::value, "");
static_assert(is_same<coord_t, typename Image::y_coord_t>::value, "");
}
Image image;
};
Expand Down
20 changes: 10 additions & 10 deletions include/boost/gil/concepts/image_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,22 @@ struct RandomAccessNDImageViewConcept
gil_function_requires<boost_concepts::RandomAccessTraversalConcept<first_it_type>>();
gil_function_requires<boost_concepts::RandomAccessTraversalConcept<last_it_type>>();

// BOOST_STATIC_ASSERT((typename std::iterator_traits<first_it_type>::difference_type, typename point_t::template axis<0>::coord_t>::value));
// BOOST_STATIC_ASSERT((typename std::iterator_traits<last_it_type>::difference_type, typename point_t::template axis<N-1>::coord_t>::value));
// static_assert(typename std::iterator_traits<first_it_type>::difference_type, typename point_t::template axis<0>::coord_t>::value, "");
// static_assert(typename std::iterator_traits<last_it_type>::difference_type, typename point_t::template axis<N-1>::coord_t>::value, "");

// point_t must be an N-dimensional point, each dimension of which must have the same type as difference_type of the corresponding iterator
gil_function_requires<PointNDConcept<point_t>>();
BOOST_STATIC_ASSERT(point_t::num_dimensions==N);
BOOST_STATIC_ASSERT((is_same
static_assert(point_t::num_dimensions == N, "");
static_assert(is_same
<
typename std::iterator_traits<first_it_type>::difference_type,
typename point_t::template axis<0>::coord_t
>::value));
BOOST_STATIC_ASSERT((is_same
>::value, "");
static_assert(is_same
<
typename std::iterator_traits<last_it_type>::difference_type,
typename point_t::template axis<N-1>::coord_t
>::value));
>::value, "");

point_t p;
locator lc;
Expand Down Expand Up @@ -215,7 +215,7 @@ struct RandomAccess2DImageViewConcept
void constraints()
{
gil_function_requires<RandomAccessNDImageViewConcept<View>>();
BOOST_STATIC_ASSERT(View::num_dimensions==2);
static_assert(View::num_dimensions == 2, "");

// TODO: This executes the requirements for RandomAccessNDLocatorConcept again. Fix it to improve compile time
gil_function_requires<RandomAccess2DLocatorConcept<typename View::locator>>();
Expand Down Expand Up @@ -373,7 +373,7 @@ struct ImageViewConcept
// TODO: This executes the requirements for RandomAccess2DLocatorConcept again. Fix it to improve compile time
gil_function_requires<PixelLocatorConcept<typename View::xy_locator>>();

BOOST_STATIC_ASSERT((is_same<typename View::x_coord_t, typename View::y_coord_t>::value));
static_assert(is_same<typename View::x_coord_t, typename View::y_coord_t>::value, "");

using coord_t = typename View::coord_t; // 1D difference type (same for all dimensions)
std::size_t num_chan = view.num_channels(); ignore_unused_variable_warning(num_chan);
Expand Down Expand Up @@ -532,7 +532,7 @@ struct ViewsCompatibleConcept
{
void constraints()
{
BOOST_STATIC_ASSERT((views_are_compatible<V1, V2>::value));
static_assert(views_are_compatible<V1, V2>::value, "");
}
};

Expand Down
8 changes: 4 additions & 4 deletions include/boost/gil/concepts/pixel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct PixelConcept
gil_function_requires<ColorBaseConcept<P>>();
gil_function_requires<PixelBasedConcept<P>>();

BOOST_STATIC_ASSERT((is_pixel<P>::value));
static_assert(is_pixel<P>::value, "");
static const bool is_mutable = P::is_mutable;
ignore_unused_variable_warning(is_mutable);

Expand Down Expand Up @@ -99,7 +99,7 @@ struct MutablePixelConcept
void constraints()
{
gil_function_requires<PixelConcept<P>>();
BOOST_STATIC_ASSERT(P::is_mutable);
static_assert(P::is_mutable, "");
}
};

Expand Down Expand Up @@ -187,7 +187,7 @@ struct HomogeneousPixelValueConcept
{
gil_function_requires<HomogeneousPixelConcept<P>>();
gil_function_requires<Regular<P>>();
BOOST_STATIC_ASSERT((is_same<P, typename P::value_type>::value));
static_assert(is_same<P, typename P::value_type>::value, "");
}
};

Expand Down Expand Up @@ -258,7 +258,7 @@ struct PixelsCompatibleConcept
{
void constraints()
{
BOOST_STATIC_ASSERT((pixels_are_compatible<P1, P2>::value));
static_assert(pixels_are_compatible<P1, P2>::value, "");
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/boost/gil/concepts/pixel_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ struct IteratorAdaptorConcept
using base_t = typename iterator_adaptor_get_base<Iterator>::type;
gil_function_requires<boost_concepts::ForwardTraversalConcept<base_t>>();

BOOST_STATIC_ASSERT(is_iterator_adaptor<Iterator>::value);
static_assert(is_iterator_adaptor<Iterator>::value, "");
using rebind_t = typename iterator_adaptor_rebind<Iterator, void*>::type;

base_t base = it.base();
Expand Down
Loading

0 comments on commit 68fe3db

Please sign in to comment.