Skip to content

Commit

Permalink
[FIX] simplify std::ranges::enable_view overloads
Browse files Browse the repository at this point in the history
I know that this introduces a macro (SEQAN3_STD_RANGES_NAMESPACE), but
this reduces code bloat for a feature that is only used for a single
data structure right now.

This PR is also in line with #1678 to remove dependencies of our library
in the std headers.
  • Loading branch information
marehr committed Mar 22, 2020
1 parent a7278bb commit b81b777
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 61 deletions.
8 changes: 4 additions & 4 deletions include/seqan3/range/decorator/gap_decorator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,14 +889,14 @@ class gap_decorator<inner_type>::gap_decorator_iterator

} // namespace seqan

namespace seqan3::detail
namespace SEQAN3_STD_RANGES_NAMESPACE
{

//!\brief Type trait that declares any seqan3::gap_decorator to be **NOT a view**.
template <typename type>
constexpr int enable_view<seqan3::gap_decorator<type>> = 0;
constexpr bool enable_view<seqan3::gap_decorator<type>> = false;

template <typename type>
constexpr int enable_view<seqan3::gap_decorator<type> const> = 0;
constexpr bool enable_view<seqan3::gap_decorator<type> const> = false;

} // namespace seqan3::detail
} // namespace std::ranges
24 changes: 0 additions & 24 deletions include/seqan3/range/detail/enable_view.hpp

This file was deleted.

47 changes: 14 additions & 33 deletions include/seqan3/std/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@

#pragma once

#include <seqan3/range/detail/enable_view.hpp>
/*!\brief The namespace where all ranges are defined (i.e., std::ranges), this is needed for partial specialisation's
* like std::ranges::enable_view
*
* \details In this shim header we import ranges::cpp20 if the compiler does not support std::ranges natively. This
* leads to the problem that customisation points like std::ranges::enable_view are declared in different
* namespace (e.g. ranges::enable_view when shimmed), but the compiler disallows to partial specialise
* std::ranges::enable_view if it was declared in a different namespace. Thus, this macro stores in which
* namespace customisation points like enable_view were defined.
*/
#if __cpp_lib_ranges
#define SEQAN3_STD_RANGES_NAMESPACE std::ranges
#else
#define SEQAN3_STD_RANGES_NAMESPACE ranges
#endif

#if __cpp_lib_ranges // C++20 ranges available
#include <ranges>
Expand Down Expand Up @@ -76,36 +89,4 @@ namespace views = ranges::views;

} // namespace std::

// ============================================================================
// traits voodoo
// ============================================================================

namespace ranges
{

//!\brief Customises ranges type trait that indicates whether `type` is a view.
template <typename type>
//!\cond
requires (seqan3::detail::enable_view<type> == 0) || (seqan3::detail::enable_view<type> == 1)
//!\endcond
constexpr bool enable_view<type> = static_cast<bool>(seqan3::detail::enable_view<type>);

} // namespace ranges

#endif // no standard header

#if __cpp_lib_ranges

namespace std::ranges
{

//!\brief Customises std::ranges type trait that indicates whether `type` is a view.
template <typename type>
//!\cond
requires (seqan3::detail::enable_view<type> == 0) || (seqan3::detail::enable_view<type> == 1)
//!\endcond
constexpr bool enable_view<type> = static_cast<bool>(seqan3::detail::enable_view<type>);

} // namespace std::ranges

#endif // standard header

0 comments on commit b81b777

Please sign in to comment.