Blog: Articles on C++11 and Computational Finance (by Daniel J. Duffy)

Visual Studio 2022 does not suppport Gaussian integers.
... not end of world, stilll, error messages are scary for some.

Gaussian integer - Wikipedia
Code: Select all
// Not on VS2022
// std::complex<int> com(1, 1);
// std::complex<int> com2(1.0, 1);
// std::complex<float> com3(1.0, 1);
std::complex<float> com3(1.0, 2.0);
 
Code:
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/describe.hpp>
#include <boost/mp11.hpp>

template<class E> char const * enum_to_string( E e )
{
    char const * r = "(unnamed)";

    boost::mp11::mp_for_each< boost::describe::describe_enumerators<E> >([&](auto D){

        if( e == D.value ) r = D.name;

    });

    return r;
}

#include <iostream>

enum E
{
    v1 = 3,
    v2,
    v3 = 13
};

BOOST_DESCRIBE_ENUM(E, v1, v2, v3)

int main()
{
    std::cout << "E(" << v1 << "): " << enum_to_string( v1 ) << std::endl;
    std::cout << "E(" << 0 << "): " << enum_to_string( E(0) ) << std::endl;

    boost::mp11::mp_for_each< boost::describe::describe_enumerators<E> >([](auto D)
    {

        std::printf("%s: %d\n", D.name, D.value);

    });
}
 
Code:
#include <iostream>
#include <string>

#include "boost/pfr.hpp"

struct some_person {
    std::string name;
    unsigned birth_year;
};

int main() {
    some_person val{ "Edgar Allan Poe", 1809 };

    std::cout << boost::pfr::get<0>(val)                // No macro!
        << " was born in " << boost::pfr::get<1>(val);  // Works with any aggregate initializables!

    std::cout << boost::pfr::io(val);                   // Outputs: {"Edgar Allan Poe", 1809}
}
 
Back
Top Bottom