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

mp::invoke causes the meta size to increase exponentially. #72

Open
TypeCombinator opened this issue Nov 9, 2024 · 0 comments
Open

Comments

@TypeCombinator
Copy link

TypeCombinator commented Nov 9, 2024

Code: https://godbolt.org/z/WxGfz3so7

#define NTEST 1
#include <https://raw.githubusercontent.com/boost-ext/mp/main/mp>
#include <type_traits>

namespace mp::detail {

template <size_t left = 0u, size_t right = MP_SIZE - 1u, auto = [](){}>
static constexpr auto meta_size() -> size_t {
    if constexpr (left >= right) {
        return left + requires { get(info<mp::info{left}>{}); };
    } else if constexpr (constexpr auto mid = left + (right - left) / 2u;
                         requires { get(info<mp::info{mid}>{}); }) {
        return meta_size<mid + 1u, right>();
    } else {
        return meta_size<left, mid - 1u>();
    }
}

} // namespace mp::detail

int main() {
    static_assert(static_cast<std::size_t>(mp::meta<char>) == 0);
    static_assert(static_cast<std::size_t>(mp::meta<unsigned char>) == 1);
    static_assert(static_cast<std::size_t>(mp::meta<int>) == 2);

    static_assert(mp::detail::meta_size() == 3);
    {
        constexpr auto m = mp::invoke<std::add_const>(mp::meta<char*>);
        static_assert(std::is_same_v<mp::type_of<m>, char* const>);
        static_assert(mp::detail::meta_size() == 9);
    }
    {
        constexpr auto m = mp::invoke<std::add_volatile>(mp::meta<char*>);
        static_assert(std::is_same_v<mp::type_of<m>, char* volatile>);
        static_assert(mp::detail::meta_size() == 19);
    }
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant