Skip to content

Commit d2f3299

Browse files
yoneyfacebook-github-bot
authored andcommitted
Move to C++ concepts, 3/n
Summary: Convert constraints to C++ concepts. Reviewed By: alexmalyshev Differential Revision: D78572883 fbshipit-source-id: 95ecaf41013abf230b4ff5bc317177688d3a7090
1 parent af00a86 commit d2f3299

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

Jit/bytecode_offsets.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "cinderx/Common/log.h"
1212

13+
#include <concepts>
1314
#include <limits>
1415
#include <ostream>
1516
#include <type_traits>
@@ -124,7 +125,7 @@ class BCOffset : public BCOffsetBase<BCOffset> {
124125
return value() <=> other.value();
125126
}
126127

127-
template <class TInt, class = std::enable_if_t<std::is_integral_v<TInt>>>
128+
template <std::integral TInt>
128129
constexpr std::strong_ordering operator<=>(const TInt& other) const {
129130
return value() <=> other;
130131
}
@@ -133,7 +134,7 @@ class BCOffset : public BCOffsetBase<BCOffset> {
133134
return value() == other.value();
134135
}
135136

136-
template <class TInt, class = std::enable_if_t<std::is_integral_v<TInt>>>
137+
template <std::integral TInt>
137138
constexpr bool operator==(const TInt& other) const {
138139
return value() == other;
139140
}
@@ -153,7 +154,7 @@ class BCIndex : public BCOffsetBase<BCIndex> {
153154
return value() <=> other.value();
154155
}
155156

156-
template <class TInt, class = std::enable_if_t<std::is_integral_v<TInt>>>
157+
template <std::integral TInt>
157158
constexpr std::strong_ordering operator<=>(const TInt& other) const {
158159
return value() <=> other;
159160
}
@@ -162,7 +163,7 @@ class BCIndex : public BCOffsetBase<BCIndex> {
162163
return value() == other.value();
163164
}
164165

165-
template <class TInt, class = std::enable_if_t<std::is_integral_v<TInt>>>
166+
template <std::integral TInt>
166167
constexpr bool operator==(const TInt& other) const {
167168
return value() == other;
168169
}

Jit/hir/hir.h

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ class InstrT<T, opcode, Operands<arity>, Tys...>
631631
// Usage:
632632
// auto instr = T::create(<args for T's constructor>);
633633
template <typename... Args, class T1 = T>
634-
static std::enable_if_t<arity >= 0, T1>* create(Args&&... args) {
634+
requires(arity >= 0)
635+
static T1* create(Args&&... args) {
635636
auto ptr = Instr::allocate(sizeof(T1), arity);
636637
return new (ptr) T1(std::forward<Args>(args)...);
637638
}
@@ -641,53 +642,45 @@ class InstrT<T, opcode, Operands<arity>, Tys...>
641642
// Usage:
642643
// auto instr = T::create(<num_operands>, <args for T's constructor>);
643644
template <typename... Args, class T1 = T>
644-
static std::enable_if_t<arity == kVariadic, T1>* create(
645-
std::size_t num_ops,
646-
Args&&... args) {
645+
requires(arity == kVariadic)
646+
static T1* create(std::size_t num_ops, Args&&... args) {
647647
auto ptr = Instr::allocate(sizeof(T1), num_ops);
648648
return new (ptr) T1(std::forward<Args>(args)...);
649649
}
650650

651651
// Forwarding constructor for variadic `T`.
652-
template <
653-
typename... Args,
654-
int a = arity,
655-
typename = std::enable_if_t<a <= 0>>
652+
template <typename... Args, int a = arity>
653+
requires(a <= 0)
656654
explicit InstrT(Args&&... args)
657655
: InstrT<T, opcode, Tys...>(std::forward<Args>(args)...) {}
658656

659657
// Constructor for unary `T`.
660-
template <
661-
typename... Args,
662-
int a = arity,
663-
typename = std::enable_if_t<a == 1>>
658+
template <typename... Args, int a = arity>
659+
requires(a == 1)
664660
explicit InstrT(Register* reg, Args&&... args)
665661
: InstrT<T, opcode, Tys...>(std::forward<Args>(args)...) {
666662
this->operandAt(0) = reg;
667663
}
668664

669665
// TODO(mpage) - Get rid of this?
670-
template <int a = arity, typename T1 = std::enable_if_t<a == 1, Register>>
671-
T1* reg() const {
666+
template <int a = arity>
667+
requires(a == 1)
668+
Register* reg() const {
672669
return this->GetOperand(0);
673670
}
674671

675672
// Constructor for binary `T`.
676-
template <
677-
typename... Args,
678-
int a = arity,
679-
typename = std::enable_if_t<a == 2>>
673+
template <typename... Args, int a = arity>
674+
requires(a == 2)
680675
InstrT(Register* lhs, Register* rhs, Args&&... args)
681676
: InstrT<T, opcode, Tys...>(std::forward<Args>(args)...) {
682677
this->operandAt(0) = lhs;
683678
this->operandAt(1) = rhs;
684679
}
685680

686681
// Constructor for trinary `T`.
687-
template <
688-
typename... Args,
689-
int x = arity,
690-
typename = std::enable_if_t<x == 3>>
682+
template <typename... Args, int x = arity>
683+
requires(x == 3)
691684
InstrT(Register* a, Register* b, Register* c, Args&&... args)
692685
: InstrT<T, opcode, Tys...>(std::forward<Args>(args)...) {
693686
this->operandAt(0) = a;
@@ -696,10 +689,8 @@ class InstrT<T, opcode, Operands<arity>, Tys...>
696689
}
697690

698691
// Constructor for 4 operand `T`.
699-
template <
700-
typename... Args,
701-
int x = arity,
702-
typename = std::enable_if_t<x == 4>>
692+
template <typename... Args, int x = arity>
693+
requires(x == 4)
703694
InstrT(Register* a, Register* b, Register* c, Register* d, Args&&... args)
704695
: InstrT<T, opcode, Tys...>(std::forward<Args>(args)...) {
705696
this->operandAt(0) = a;

0 commit comments

Comments
 (0)