Commit 8318a862 authored by Dmytro Stechenko's avatar Dmytro Stechenko Committed by Facebook GitHub Bot

Remove std::variant dependency from Badges

Summary:
Fixed some `folly::badge` docs to make them more precise.
Renamed `folly::badges` to `folly::any_badge`.
Made `folly::any_badge` an empty class that we can only lift into from a singular `folly::badge` that is a part of the badges allowed.

Reviewed By: yfeldblum

Differential Revision: D31905323

fbshipit-source-id: f48394dda2c2c6b46169087c4231443552e056e4
parent 80961096
......@@ -16,9 +16,9 @@
#pragma once
#if __has_include(<variant>)
#include <variant>
#endif
#include <type_traits>
#include <folly/Traits.h>
namespace folly {
......@@ -54,15 +54,14 @@ class badge {
badge() {}
};
#if __has_include(<variant>)
/**
* For cases when multiple badge holders are required to call a function we can
* use std::variant<...> over individual badges.
* For cases when multiple badge holders need to call a function we can
* use folly::any_badge over each individual holder allowed.
*
* Example:
* class ProtectedClass: {
* public:
* static void func(folly::badges<FriendClass, OtherFriendClass>);
* static void func(folly::any_badge<FriendClass, OtherFriendClass>);
* };
*
* void FriendClass::callProtectedFunc() {
......@@ -73,7 +72,12 @@ class badge {
* }
*/
template <typename... Holders>
using badges = std::variant<badge<Holders>...>;
#endif
class any_badge {
public:
template <
typename Holder,
std::enable_if_t<folly::IsOneOf<Holder, Holders...>::value, int> = 0>
/* implicit */ any_badge(badge<Holder>) {}
};
} // namespace folly
......@@ -26,7 +26,7 @@ class OtherFriendClass;
using SingleBadge = folly::badge<FriendClass>;
using OtherSingleBadge = folly::badge<OtherFriendClass>;
using MultipleBadges = folly::badges<FriendClass, OtherFriendClass>;
using MultipleBadges = folly::any_badge<FriendClass, OtherFriendClass>;
class ProtectedClass {
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment