logo
down
shadow

Boost test fails with enum classes inside namespaces


Boost test fails with enum classes inside namespaces

Content Index :

Boost test fails with enum classes inside namespaces
Tag : cpp , By : ZsA
Date : November 28 2020, 09:01 AM

With these it helps You need to define the operator inside the namespace if you want to make use of ADL.
#include <iostream>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE EnumExample
#include <boost/test/unit_test.hpp>

namespace A {

enum class Example {
    One,
    Two,
};


std::ostream& operator<< (std::ostream& s, Example e)
{
    switch (e) {
        case A::Example::One: s << "Example::One"; break;
        case A::Example::Two: s << "Example::Two"; break;
    }
    return s;
}

} // namespace A

BOOST_AUTO_TEST_CASE(enum_example)
{
    A::Example a = A::Example::One;
    A::Example b = A::Example::Two;

    // The following line works with or without the namespace
    std::cout << a << std::endl;

    // The following line does not work with the namespace - why?
    BOOST_REQUIRE_EQUAL(a, b);
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Use enum classes with Boost Test


Tag : cpp , By : Menno
Date : March 29 2020, 07:55 AM
I wish this help you You can disable printing of the type in question with BOOST_TEST_DONT_PRINT_LOG_VALUE(). From the Boost docs:
typedef std::pair<int,float> pair_type;

BOOST_TEST_DONT_PRINT_LOG_VALUE( pair_type )

Boost Python 1.48 fails when exporting 32 bit enum


Tag : python , By : Frank Rotolo
Date : March 29 2020, 07:55 AM
this one helps. EDIT: Found by Tigger at work, documenting here for posterity:
Problem is in the definition of the enum_object struct. The underlying digit storage in base_object allows for either 15-bit digit (as shorts) or 30-bit digit (as int) granularity, but the base_object only contains enough space for either 2x 15-bit digits or 1x 30-bit digits. When a > 30-bit enumeration value is stored the encoding requires either 3 shorts or 2 ints depending on the format compiled. The result is that the name member occupies the space needed for the extra digit storage. The reference decrement fails because the value is laid into place where the name member expects to be.
struct enum_object
{
#if PY_VERSION_HEX >= 0x03000000
   PyLongObject base_object;
#else
   PyIntObject base_object;
#endif
   // ADD PADDING HERE TO FIX ALIGNMENT ISSUE
   PyObject* name;
};
void enum_base::add_value(char const* name_, long value)
{
    // Convert name to Python string
    object name(name_);

    // Create a new enum instance by calling the class with a value
    object x = (*this)(value);

    // Store the object in the enum class
    (*this).attr(name_) = x;

    dict d = extract<dict>(this->attr("values"))();
    d[value] = x;

    // Set the name field in the new enum instanec
    enum_object* p = downcast<enum_object>(x.ptr());
    Py_XDECREF(p->name);
    p->name = incref(name.ptr());

    dict names_dict = extract<dict>(this->attr("names"))();
    names_dict[x.attr("name")] = x;
}

enum, classes, namespaces and long names


Tag : cpp , By : Big Ant
Date : March 29 2020, 07:55 AM
it helps some times First, you repeat stuff:
The name kSensorActive doesn't have to say Sensor if you already specified that it's a SensorStatus in the name. Or you could remove Sensor from SensorStatus if it's inside MySensor. Maybe both.
using Status = Sensors::MySensor::SensorStatus;

How to test Controllers under different namespaces and why this test fails?


Tag : ruby-on-rails , By : Laques
Date : November 28 2020, 01:01 AM

C# Namespaces inside classes?


Tag : chash , By : user181706
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Can I get a pointer to a pointer pointing to nullptr, is it valid
  • Most elegant way to split a C++ TypeList
  • How to access element of JSON using Qt
  • find the inorder traversal of the tree and print them all by negating every alternate number
  • How to compile a static library with Codelite 11.0.0?
  • Could this publish / check-for-update class for a single writer + reader use memory_order_relaxed or acquire/release for
  • Passing a function identifier as an rvalue reference and applying std::move() to it
  • The conditional operator is not allowing the program to terminate
  • Define a c++ string as "\"
  • memcpy on __declspec naked returns unexpected bytes
  • What is the proper way to link enums with CMake?
  • is it safe to use the same mutex with lock_gard and without it in other parts of code
  • How to decode MAP Invoke messages using asn1c generated code
  • How do you write multiple lines in a .txt with recursion?
  • Member function with strange type causing callback function mismatch
  • Visual Studio optimisations break SDL graphical output
  • How to use less memory in Sieve_of_Eratosthenes
  • Covariance in Callback Parameters C++
  • switch may fall through (no it may not)
  • Compilation fails calling Cocoa function from C++
  • How to handle classes with differently named member functions in algorithms?
  • Convert QString to QJsonArray
  • Data exchange finished in CPropertyPage::OnOK?
  • Template member specialization in template class
  • Is it not possible to assign a struct to an index of a vector?
  • Why is empty unordered_map.find not returning end()?
  • Template argument deduction for inheriting specializations
  • dlopen undefined reference
  • Member function of class with template arguments and default arguments outside class
  • Is it possible to implement a non-owning "slightly smart" pointer on top of standard weak pointers?
  • how to configure the AcquireCredentialsHandleA correctly
  • Using private versions of global extern variables with OpenMP
  • Eigen Block wrong amount of columns and rows
  • Memory alignment rules in inheritance
  • Is nullptr falsy?
  • tm_wday returns a large integer outside 0-6 range
  • Scope a using declaration, inside a header
  • How to specify constructor's template arguments inside a new expression?
  • Sort an array via x86 Assembly (embedded in C++)?? Possible?
  • How to Replace only Part of the Variable using #define
  • How do you compare the performace of valarrays vs built-in arrays?
  • Is it normal for C++ static initialization to appear twice in the same backtrace?
  • c++ generate a good random seed for psudo random number generators
  • Why isn't my operator overloading working properly?
  • Getting meaningful error messages from fstream's in C++
  • C++: Converting Julian dates to Gregorian
  • Could someone explain this interesting behaviour with Sleep(1)?
  • Is it possible to roll a significantly faster version of modf
  • Updating pointer using signals and slots
  • How are classes more secure than structures?
  • finding "distance" between two pixel's colors
  • C++ Greatest Number Verification
  • Why does my token return NULL and how can I fix it?(c++)
  • C++ enforce conditions on inherited classes
  • what happened if an exception is not captured?
  • Redundant naming in C/C++ typedefs/structs
  • question about STL thread-safe and STL debugging
  • killing a separate thread having a socket
  • Returning the size of available virtual memory at run-time in C++
  • Parallel computing for integrals
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com