// // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/url // #include #include #include #include namespace boost { namespace urls { template template void router:: insert(core::string_view pattern, U&& v) { BOOST_STATIC_ASSERT( std::is_same::value || std::is_convertible::value || std::is_base_of::value); using U_ = typename std::decay< typename std::conditional< std::is_base_of::value, U, T >::type>::type; struct impl : any_resource { U_ u; explicit impl(U&& u_) : u(std::forward(u_)) { } void const* get() const noexcept override { return static_cast(&u); } }; any_resource const* p = new impl( std::forward(v)); insert_impl( pattern, p ); } template T const* router:: find(segments_encoded_view path, matches_base& m) const noexcept { core::string_view* matches_it = m.matches(); core::string_view* ids_it = m.ids(); any_resource const* p = find_impl( path, matches_it, ids_it ); if (p) { BOOST_ASSERT(matches_it >= m.matches()); m.resize(static_cast( matches_it - m.matches())); return reinterpret_cast< T const*>(p->get()); } m.resize(0); return nullptr; } } // urls } // boost