Skip to content

Commit

Permalink
Replace BOOST_STATIC_ASSERT with static_assert
Browse files Browse the repository at this point in the history
Since we now require C++11, we can use the standard
static_assert, which should give better compiler
diagnostics than the Boost macro.
  • Loading branch information
benmwebb committed Feb 1, 2024
1 parent 4eebf94 commit de833bb
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions include/RMF/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ class Vector
RMF_CXX11_DEFAULT_COPY_CONSTRUCTOR(Vector);

Vector(float x, float y, float z) {
BOOST_STATIC_ASSERT(D == 3);
static_assert(D == 3);
P::operator[](0) = x;
P::operator[](1) = y;
P::operator[](2) = z;
}
Vector(float x, float y, float z, float q) {
BOOST_STATIC_ASSERT(D == 4);
static_assert(D == 4);
P::operator[](0) = x;
P::operator[](1) = y;
P::operator[](2) = z;
Expand Down
6 changes: 3 additions & 3 deletions include/RMF/internal/swig_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct ValueOrObject {

template <class T>
struct ConvertAllBase {
BOOST_STATIC_ASSERT(!is_pointer<T>::value);
static_assert(!is_pointer<T>::value);
template <class SwigData>
static bool get_is_cpp_object(PyObject* o, SwigData st) {
void* vp;
Expand All @@ -129,7 +129,7 @@ struct ConvertAllBase {

template <class T>
struct ConvertValueBase : public ConvertAllBase<T> {
BOOST_STATIC_ASSERT(!is_pointer<T>::value);
static_assert(!is_pointer<T>::value);
template <class SwigData>
static const T& get_cpp_object(PyObject* o, SwigData st) {
void* vp;
Expand Down Expand Up @@ -175,7 +175,7 @@ struct Convert : public ConvertValueBase<T> {
template <class T, class VT, class ConvertVT>
struct ConvertSequenceHelper {
typedef typename ValueOrObject<VT>::type V;
BOOST_STATIC_ASSERT(!is_pointer<T>::value);
static_assert(!is_pointer<T>::value);
template <class SwigData>
static bool get_is_cpp_object(PyObject* in, SwigData st) {
if (!in || !PySequence_Check(in)) {
Expand Down
4 changes: 2 additions & 2 deletions src/avrocpp/api/AvroParse.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ void parse(ResolvingReader &p, T &val) {

template <typename Reader, typename T>
void parse(Reader &p, T &val, const boost::false_type &) {
BOOST_STATIC_ASSERT(sizeof(T) == 0);
static_assert(sizeof(T) == 0);
}

template <typename Reader, typename T>
void translatingParse(Reader &p, T &val, const boost::false_type &) {
BOOST_STATIC_ASSERT(sizeof(T) == 0);
static_assert(sizeof(T) == 0);
}

// @{
Expand Down
2 changes: 1 addition & 1 deletion src/avrocpp/api/AvroSerialize.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void serialize(Writer &s, const T &val) {

template <typename Writer, typename T>
void serialize(Writer &s, const T &val, const boost::false_type &) {
BOOST_STATIC_ASSERT(sizeof(T) == 0);
static_assert(sizeof(T) == 0);
}

/// The remainder of the file includes default implementations for serializable
Expand Down
2 changes: 1 addition & 1 deletion src/avrocpp/api/buffer/BufferReader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class AVRO_DECL BufferReader : private boost::noncopyable {
/// An uninstantiable function, this is if boost::is_fundamental check fails
template <typename T>
bool read(T &val, const boost::false_type &) {
BOOST_STATIC_ASSERT(sizeof(T) == 0);
static_assert(sizeof(T) == 0);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/avrocpp/api/buffer/detail/BufferDetail.hh
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class BufferImpl : boost::noncopyable {
/// and will compile-time assert.
template <typename T>
void writeTo(T val, const boost::false_type &) {
BOOST_STATIC_ASSERT(sizeof(T) == 0);
static_assert(sizeof(T) == 0);
}

/// Write a block of data to the buffer, adding new chunks if necessary.
Expand Down
8 changes: 4 additions & 4 deletions src/avrocpp/impl/Resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ class ResolverFactory : private boost::noncopyable {
&ResolverFactory::constructCompound<UnionParser, UnionSkipper>,
&ResolverFactory::constructCompound<FixedParser, FixedSkipper>};

BOOST_STATIC_ASSERT((sizeof(funcs) / sizeof(BuilderFunc)) ==
(AVRO_NUM_TYPES));
static_assert((sizeof(funcs) / sizeof(BuilderFunc)) ==
(AVRO_NUM_TYPES));

BuilderFunc func = funcs[currentWriter->type()];
assert(func);
Expand Down Expand Up @@ -594,8 +594,8 @@ class ResolverFactory : private boost::noncopyable {
&ResolverFactory::constructCompoundSkipper<UnionSkipper>,
&ResolverFactory::constructCompoundSkipper<FixedSkipper>};

BOOST_STATIC_ASSERT((sizeof(funcs) / sizeof(BuilderFunc)) ==
(AVRO_NUM_TYPES));
static_assert((sizeof(funcs) / sizeof(BuilderFunc)) ==
(AVRO_NUM_TYPES));

BuilderFunc func = funcs[currentWriter->type()];
assert(func);
Expand Down
6 changes: 3 additions & 3 deletions src/avrocpp/impl/Types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ const std::string typeToString[] = {
"string", "bytes", "int", "long", "float", "double", "boolean", "null",
"record", "enum", "array", "map", "union", "fixed", "symbolic"};

BOOST_STATIC_ASSERT((sizeof(typeToString) / sizeof(std::string)) ==
(AVRO_NUM_TYPES + 1));
static_assert((sizeof(typeToString) / sizeof(std::string)) ==
(AVRO_NUM_TYPES + 1));

} // namespace strings

// this static assert exists because a 32 bit integer is used as a bit-flag for
// each type,
// and it would be a problem for this flag if we ever supported more than 32
// types
BOOST_STATIC_ASSERT(AVRO_NUM_TYPES < 32);
static_assert(AVRO_NUM_TYPES < 32);

const std::string &toString(Type type) {
static std::string undefinedType = "Undefined type";
Expand Down
6 changes: 3 additions & 3 deletions src/avrocpp/impl/Validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void Validator::doAdvance() {
&Validator::enumAdvance, &Validator::countingAdvance,
&Validator::countingAdvance, &Validator::unionAdvance,
&Validator::fixedAdvance};
BOOST_STATIC_ASSERT((sizeof(funcs) / sizeof(AdvanceFunc)) ==
(AVRO_NUM_TYPES));
static_assert((sizeof(funcs) / sizeof(AdvanceFunc)) ==
(AVRO_NUM_TYPES));

expectedTypesFlag_ = 0;
// loop until we encounter a next expected type, or we've exited all compound
Expand Down Expand Up @@ -199,7 +199,7 @@ void Validator::setupFlag(Type type) {
typeToFlag(AVRO_ENUM), typeToFlag(AVRO_ARRAY),
typeToFlag(AVRO_MAP), typeToFlag(AVRO_UNION),
typeToFlag(AVRO_FIXED)};
BOOST_STATIC_ASSERT((sizeof(flags) / sizeof(flag_t)) == (AVRO_NUM_TYPES));
static_assert((sizeof(flags) / sizeof(flag_t)) == (AVRO_NUM_TYPES));

expectedTypesFlag_ = flags[type];
}
Expand Down

0 comments on commit de833bb

Please sign in to comment.