Replace SFINAE with concepts (#5361)

Concepts are cleaner to use and result in much better error messages for incorrect template use.
This commit is contained in:
Tyler Veness
2023-06-07 09:50:09 -07:00
committed by GitHub
parent d57d1a4598
commit 91cbcea841
42 changed files with 397 additions and 361 deletions

View File

@@ -10,6 +10,8 @@
#include <utility>
#include <vector>
#include "wpi/concepts.h"
namespace wpi {
/**
@@ -22,11 +24,9 @@ namespace wpi {
*/
template <typename T, typename Sequence = std::vector<T>,
typename Compare = std::less<typename Sequence::value_type>>
requires std::same_as<T, typename Sequence::value_type>
class priority_queue {
public:
static_assert(std::is_same_v<T, typename Sequence::value_type>,
"value_type must be the same as the underlying container");
using value_type = typename Sequence::value_type;
using reference = typename Sequence::reference;
using const_reference = typename Sequence::const_reference;
@@ -34,10 +34,9 @@ class priority_queue {
using container_type = Sequence;
using value_compare = Compare;
template <typename Seq = Sequence,
typename Requires = typename std::enable_if_t<
std::is_default_constructible<Compare>{} &&
std::is_default_constructible<Seq>{}>>
template <typename Seq = Sequence>
requires std::default_initializable<Compare> &&
std::default_initializable<Seq>
priority_queue() {}
priority_queue(const Compare& comp, const Sequence& c) : c(c), comp(comp) {