18 #define FOLLY_GEN_BASE_H_ 24 #include <type_traits> 25 #include <unordered_map> 26 #include <unordered_set> 88 template <
class First,
class Second>
90 -> decltype(
first < second) {
91 return first < second;
97 template <
class First,
class Second>
99 -> decltype(
first > second) {
100 return first > second;
107 template <
class Value>
110 return std::get<n>(std::forward<Value>(
value));
114 template <
class Class,
class Result>
117 typedef Result (Class::*MemberPtr)();
126 return (
x.*member_)();
130 return (x.*member_)();
134 return (x->*member_)();
138 template <
class Class,
class Result>
141 typedef Result (Class::*MemberPtr)()
const;
150 return (x.*member_)();
154 return (x->*member_)();
158 template <
class Class,
class FieldType>
192 template <
class Value>
195 return std::move(std::forward<Value>(value));
202 template <
class Predicate>
213 return !pred_(std::forward<Arg>(arg));
216 template <
class Predicate>
221 template <
class Dest>
224 template <
class Value>
226 return Dest(std::forward<Value>(
value));
230 template <
class Dest>
233 template <
class Value>
235 return ::folly::to<Dest>(std::forward<Value>(
value));
239 template <
class Dest>
242 template <
class Value>
244 return ::folly::tryTo<Dest>(std::forward<Value>(
value));
257 template <
class Key,
class Value>
262 template <
class Self>
268 template <
class Container>
288 template <
class Value,
class SequenceImpl>
291 template <
class Value>
294 template <
class Value,
class Distance>
297 template <
class Value>
300 template <
class Value,
class Distance>
303 template <
class Value>
306 template <
class Value,
class Source>
309 template <
class Value>
312 template <
class Value>
315 template <
class Value>
321 template <
class Predicate>
324 template <
class Predicate>
327 template <
class Predicate>
334 template <
class Rand>
339 template <
class Visitor>
342 template <
class Selector,
class Comparer = Less>
345 template <
class Selector>
348 template <
class Selector>
351 template <
class Selector>
354 template <
class Operators>
357 template <
class Expected>
364 template <
bool forever>
378 template <
class Seed,
class Fold>
383 template <
bool result>
386 template <
class Reducer>
391 template <
class Selector,
class Comparer>
394 template <
class Container>
398 template <
class,
class>
class Collection = std::vector,
399 template <
class>
class Allocator = std::allocator>
402 template <
class Collection>
405 template <
class Value>
408 template <
class Needle>
411 template <
class Exception,
class ErrorHandler>
424 template <
class Value>
434 return From(&source);
437 template <
class Container,
class From = detail::ReferencedSource<Container>>
439 return From(&source);
447 return CopyOf(std::forward<Container>(source));
450 template <
class Value,
class From = detail::CopiedSource<Value>>
451 From
from(std::initializer_list<Value> source) {
459 From
from(Container&& source) {
505 template <
class Value,
class Source,
class Yield = detail::Yield<Value, Source>>
507 return Yield(std::forward<Source>(source));
515 #define GENERATOR(TYPE) \ 516 ::folly::gen::detail::GeneratorBuilder<TYPE>() + [=](auto&& yield) 521 template <
class Value>
528 class Just =
typename std::conditional<
533 return Just(std::forward<Value>(
value));
539 template <
class Predicate,
class Map = detail::Map<Predicate>>
544 template <
class Predicate,
class Map = detail::Map<Predicate>>
558 template <
class Operator,
class Map = detail::Map<detail::Composer<Operator>>>
585 template <MemberType Constness>
592 template <MemberType Constness>
606 Return (Class::*
member)()
const) {
607 return Map(Mem(member));
617 Return (Class::*member)()) {
618 return Map(Mem(member));
645 template <
class Predicate = Identity,
class Filter = detail::Filter<Predicate>>
646 Filter
filter(Predicate pred = Predicate()) {
650 template <
class Visitor = Ignore,
class Visit = detail::Visit<Visitor>>
651 Visit
visit(Visitor visitor = Visitor()) {
655 template <
class Predicate = Identity,
class Until = detail::Until<Predicate>>
656 Until
until(Predicate pred = Predicate()) {
669 class Comparer =
Less,
671 Order
orderBy(Selector selector = Selector(), Comparer comparer = Comparer()) {
682 template <
class Selector = Identity,
class GroupBy = detail::GroupBy<Selector>>
683 GroupBy
groupBy(Selector selector = Selector()) {
691 return GroupByAdjacent(
std::move(selector));
701 template <
int n,
class Get = detail::Map<Get<n>>>
707 template <
class Dest,
class Cast = detail::Map<Cast<Dest>>>
713 template <
class Dest,
class EachTo = detail::Map<To<Dest>>>
719 template <
class Dest,
class EachTryTo = detail::Map<TryTo<Dest>>>
724 template <
class Value>
758 Composed
any(Predicate pred = Predicate()) {
759 return Composed(Filter(
std::move(pred)), NotEmpty());
786 Composed
all(Predicate pred = Predicate()) {
790 template <
class Seed,
class Fold,
class FoldLeft = detail::FoldLeft<Seed, Fold>>
795 template <
class Reducer,
class Reduce = detail::Reduce<Reducer>>
796 Reduce
reduce(Reducer reducer = Reducer()) {
800 template <
class Selector = Identity,
class Min = detail::Min<Selector, Less>>
801 Min
minBy(Selector selector = Selector()) {
805 template <
class Selector,
class MaxBy = detail::Min<Selector, Greater>>
806 MaxBy
maxBy(Selector selector = Selector()) {
810 template <
class Collection,
class Collect = detail::Collect<Collection>>
816 template <
class,
class>
class Container = std::vector,
817 template <
class>
class Allocator = std::allocator,
823 template <
class Collection,
class Append = detail::Append<Collection>>
825 return Append(&collection);
841 return GuardImpl(std::forward<ErrorHandler>(
handler));
848 return UnwrapOr(std::forward<Fallback>(fallback));
Result operator()(Class &&x) const
decltype(*std::begin(std::declval< Container & >())) RefType
Yield generator(Source &&source)
Result operator()(const Class *x) const
CopyOf fromCopy(Container &&source)
FieldTypeClass::* FieldPtr
Expected< Dest, ConversionCode > operator()(Value &&value) const
Negate< Predicate > negate(Predicate pred)
Result operator()(Class *x) const
Map field(FieldType Class::*field)
From from(Container &source)
StringPiece operator()(StringPiece src) const
constexpr detail::Map< Move > move
auto begin(TestAdlIterable &instance)
Reduce reduce(Reducer reducer=Reducer())
Gen seq(Value first, Value last)
typename std::decay< RefType >::type StorageType
Visit visit(Visitor visitor=Visitor())
bool operator()(Arg &&arg) const
—— Concurrent Priority Queue Implementation ——
Min minBy(Selector selector=Selector())
std::unordered_map< int64_t, VecT > Map
auto operator()(Value &&value) const -> decltype(std::move(std::forward< Value >(value)))
FieldType & operator()(Class *x) const
Dest operator()(Value &&value) const
Composed any(Predicate pred=Predicate())
FieldType & operator()(Class &x) const
void handler(int, siginfo_t *, void *)
Gen range(Value begin, Value end)
ConstMemberFunction(MemberPtr member)
FoldLeft foldl(Seed seed=Seed(), Fold fold=Fold())
GroupByAdjacent groupByAdjacent(Selector selector=Selector())
const FieldType & operator()(const Class &x) const
Order orderByDescending(Selector selector=Selector())
auto operator()(const First &first, const Second &second) const -> decltype(first< second)
auto operator()(Value &&value) const -> decltype(std::get< n >(std::forward< Value >(value)))
UnwrapOr unwrapOr(Fallback &&fallback)
bool Value(const T &value, M matcher)
Order orderBy(Selector selector=Selector(), Comparer comparer=Comparer())
Contains contains(Needle &&needle)
From fromConst(const Container &source)
auto end(TestAdlIterable &instance)
Dest operator()(Value &&value) const
GuardImpl guard(ErrorHandler &&handler)
Map map(Predicate pred=Predicate())
Result operator()(const Class &x) const
Result operator()(Class &x) const
TakeWhile takeWhile(Predicate pred=Predicate())
PolymorphicMatcher< internal::FieldMatcher< Class, FieldType > > Field(FieldType Class::*field, const FieldMatcher &matcher)
Append appendTo(Collection &collection)
static const char *const value
Filter filter(Predicate pred=Predicate())
std::enable_if< ExprIsConst< Constness >::value, Map >::type member(Return(Class::*member)() const)
Distinct distinctBy(Selector selector=Selector())
MaxBy maxBy(Selector selector=Selector())
Until until(Predicate pred=Predicate())
detail::Empty< Value > empty()
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN auto fold(Fn &&, A &&a)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
Map mapped(Predicate pred=Predicate())
FieldType && operator()(Class &&x) const
auto operator()(const First &first, const Second &second) const -> decltype(first > second)
internal::ContainsMatcher< M > Contains(M matcher)
const FieldType & operator()(const Class *x) const
detail::TypeAssertion< Value > assert_type()
GroupBy groupBy(Selector selector=Selector())
internal::ReturnAction< R > Return(R value)
MemberFunction(MemberPtr member)
constexpr detail::First first
Composed all(Predicate pred=Predicate())