These are chat archives for bluescarni/pagmo_reborn

2nd
Jul 2016
Francesco Biscani
@bluescarni
Jul 02 2016 11:20
the final draft of C++17 is now feature complete. Look at this beauty:
auto get_tuple()
{
    return {1,4.5,"hello world"_s};
}

auto [n,x,s] = get_tuple();
basically python
Francesco Biscani
@bluescarni
Jul 02 2016 11:27

the constexpr if allows to rewrite this:

    template <typename U, typename std::enable_if<pagmo::has_gradient_sparsity<U>::value,int>::type = 0>
    sparsity_pattern gradient_sparsity_impl(const U &p) const
    {
        return p.gradient_sparsity();
    }
    template <typename U, typename std::enable_if<!pagmo::has_gradient_sparsity<U>::value,int>::type = 0>
    sparsity_pattern gradient_sparsity_impl(const U &) const
    {
        pagmo_throw(std::logic_error,"gradient_sparsity() was signalled as present in the user-defined problem, but it is not actually implemented: this "
            "indicates a logical error in the implementation of the user-defined problem class");
    }

as

template <typename U>
auto gradient_sparsity_impl(const U &p)
{
    if constexpr (pagmo::has_gradient_sparsity<U>::value) {
        return p.gradient_sparsity();
    } else {
        pagmo_throw(std::logic_error,"gradient_sparsity() was signalled as present in the user-defined problem, but it is not actually implemented: this "
            "indicates a logical error in the implementation of the user-defined problem class");
    }
}