Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved performance of mp_is_set #100

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion include/boost/mp11/set.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef BOOST_MP11_SET_HPP_INCLUDED
#define BOOST_MP11_SET_HPP_INCLUDED

// Copyright 2015, 2019 Peter Dimov.
// Copyright 2015, 2019, 2024 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
Expand All @@ -10,9 +10,11 @@

#include <boost/mp11/utility.hpp>
#include <boost/mp11/function.hpp>
#include <boost/mp11/detail/config.hpp>
#include <boost/mp11/detail/mp_list.hpp>
#include <boost/mp11/detail/mp_append.hpp>
#include <boost/mp11/detail/mp_copy_if.hpp>
#include <boost/mp11/detail/mp_fold.hpp>
#include <boost/mp11/detail/mp_remove_if.hpp>
#include <boost/mp11/detail/mp_is_list.hpp>
#include <type_traits>
Expand Down Expand Up @@ -94,6 +96,34 @@ template<class S, class... T> using mp_set_push_front = typename detail::mp_set_
namespace detail
{

#if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 )

struct mp_is_set_helper_start
{
static constexpr bool value = true;
template<class T> static mp_false contains( T );
};

template<class Base, class T>
struct mp_is_set_helper: Base
{
static constexpr bool value = Base::value && !decltype( Base::contains( mp_identity<T>{} ) )::value;
using Base::contains;
static mp_true contains( mp_identity<T> );
};

template<class S> struct mp_is_set_impl
{
using type = mp_false;
};

template<template<class...> class L, class... T> struct mp_is_set_impl<L<T...>>
{
using type = mp_bool<mp_fold<mp_list<T...>, detail::mp_is_set_helper_start, detail::mp_is_set_helper>::value>;
};

#else

template<class S> struct mp_is_set_impl
{
using type = mp_false;
Expand All @@ -104,6 +134,8 @@ template<template<class...> class L, class... T> struct mp_is_set_impl<L<T...>>
using type = mp_to_bool<std::is_same<mp_list<T...>, mp_set_push_back<mp_list<>, T...> > >;
};

#endif // !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 )

} // namespace detail

template<class S> using mp_is_set = typename detail::mp_is_set_impl<S>::type;
Expand Down
Loading