// Conversion ctor for interoperability between const_iterator and
// iterator. The enable_if<> magic keeps us well-behaved for
// is_convertible<> (v. the iterator_facade documentation).
- template<class OtherContT, class OtherVal>
+ template <class OtherContT, class OtherVal>
aha_iterator(const aha_iterator<OtherContT,OtherVal>& o,
typename std::enable_if<
std::is_convertible<OtherVal*,IterVal*>::value >::type* = 0)
const KeyT kLockedKey_;
const KeyT kErasedKey_;
- template<class ContT, class IterVal>
+ template <class ContT, class IterVal>
struct aha_iterator;
typedef aha_iterator<const AtomicHashArray,const value_type> const_iterator;
// Conversion ctor for interoperability between const_iterator and
// iterator. The enable_if<> magic keeps us well-behaved for
// is_convertible<> (v. the iterator_facade documentation).
- template<class OtherContT, class OtherVal, class OtherSubIt>
+ template <class OtherContT, class OtherVal, class OtherSubIt>
ahm_iterator(const ahm_iterator<OtherContT,OtherVal,OtherSubIt>& o,
typename std::enable_if<
std::is_convertible<OtherSubIt,SubIt>::value >::type* = 0)
{}
};
-template<class KeyT, class ValueT, class HashFcn, class EqualFcn,
- class Allocator, class ProbeFcn, class KeyConvertFcn>
+template <
+ class KeyT,
+ class ValueT,
+ class HashFcn,
+ class EqualFcn,
+ class Allocator,
+ class ProbeFcn,
+ class KeyConvertFcn>
class AtomicHashMap : boost::noncopyable {
typedef AtomicHashArray<KeyT, ValueT, HashFcn, EqualFcn,
Allocator, ProbeFcn, KeyConvertFcn>
typedef std::size_t size_type;
typedef typename SubMap::Config Config;
- template<class ContT, class IterVal, class SubIt>
+ template <class ContT, class IterVal, class SubIt>
struct ahm_iterator;
typedef ahm_iterator<const AtomicHashMap,
/// type <= 8 bytes.
template <
typename T,
- template<typename> class Atom = std::atomic,
+ template <typename> class Atom = std::atomic,
typename Raw = typename detail::AtomicStructIntPick<sizeof(T)>::type>
class AtomicStruct {
static_assert(alignof(T) <= alignof(Raw),
/// which is much faster than destructing all of the keys and values.
/// Feel free to override if std::is_trivial_destructor isn't recognizing
/// the triviality of your destructors.
-template <typename Key,
- typename Value,
- typename Hash = std::hash<Key>,
- typename KeyEqual = std::equal_to<Key>,
- bool SkipKeyValueDeletion =
- (boost::has_trivial_destructor<Key>::value &&
- boost::has_trivial_destructor<Value>::value),
- template<typename> class Atom = std::atomic,
- typename IndexType = uint32_t,
- typename Allocator = folly::detail::MMapAlloc>
+template <
+ typename Key,
+ typename Value,
+ typename Hash = std::hash<Key>,
+ typename KeyEqual = std::equal_to<Key>,
+ bool SkipKeyValueDeletion =
+ (boost::has_trivial_destructor<Key>::value &&
+ boost::has_trivial_destructor<Value>::value),
+ template <typename> class Atom = std::atomic,
+ typename IndexType = uint32_t,
+ typename Allocator = folly::detail::MMapAlloc>
struct AtomicUnorderedInsertMap {
/// auto value = memo.findOrConstruct(key, [=](void* raw) {
/// new (raw) std::string(computation(key));
/// })->first;
- template<typename Func>
+ template <typename Func>
std::pair<const_iterator,bool> findOrConstruct(const Key& key, Func&& func) {
auto const slot = keyToSlotIdx(key);
auto prev = slots_[slot].headAndState_.load(std::memory_order_acquire);
/// Eventually we can duplicate all of the std::pair constructor
/// forms, including a recursive tuple forwarding template
/// http://functionalcpp.wordpress.com/2013/08/28/tuple-forwarding/).
- template<class K, class V>
+ template <class K, class V>
std::pair<const_iterator,bool> emplace(const K& key, V&& value) {
return findOrConstruct(key, [&](void* raw) {
new (raw) Value(std::forward<V>(value));
/// updating values inserted into an AtomicUnorderedInsertMap<K,
/// MutableAtom<V>>. This relies on AtomicUnorderedInsertMap's guarantee
/// that it doesn't move values.
-template <typename T,
- template<typename> class Atom = std::atomic>
+template <typename T, template <typename> class Atom = std::atomic>
struct MutableAtom {
mutable Atom<T> data;
namespace folly { namespace detail {
-template<typename ValT, typename NodeT> class csl_iterator;
+template <typename ValT, typename NodeT> class csl_iterator;
-template<typename T>
+template <typename T>
class SkipListNode : private boost::noncopyable {
enum : uint16_t {
IS_HEAD_NODE = 1,
public:
typedef T value_type;
- template<typename NodeAlloc, typename U,
- typename=typename std::enable_if<std::is_convertible<U, T>::value>::type>
+ template <
+ typename NodeAlloc,
+ typename U,
+ typename =
+ typename std::enable_if<std::is_convertible<U, T>::value>::type>
static SkipListNode* create(
NodeAlloc& alloc, int height, U&& data, bool isHead = false) {
DCHECK(height >= 1 && height < 64) << height;
return node;
}
- template<typename NodeAlloc>
+ template <typename NodeAlloc>
static void destroy(NodeAlloc& alloc, SkipListNode* node) {
node->~SkipListNode();
alloc.deallocate(node);
}
- template<typename NodeAlloc>
+ template <typename NodeAlloc>
struct DestroyIsNoOp : std::integral_constant<bool,
IsArenaAllocator<NodeAlloc>::value &&
boost::has_trivial_destructor<SkipListNode>::value> { };
private:
// Note! this can only be called from create() as a placement new.
- template<typename U>
+ template <typename U>
SkipListNode(uint8_t height, U&& data, bool isHead) :
height_(height), data_(std::forward<U>(data)) {
spinLock_.init();
size_t sizeLimitTable_[kMaxHeight];
};
-template<typename NodeType, typename NodeAlloc, typename = void>
+template <typename NodeType, typename NodeAlloc, typename = void>
class NodeRecycler;
-template<typename NodeType, typename NodeAlloc>
+template <typename NodeType, typename NodeAlloc>
class NodeRecycler<NodeType, NodeAlloc, typename std::enable_if<
!NodeType::template DestroyIsNoOp<NodeAlloc>::value>::type> {
public:
// In case of arena allocator, no recycling is necessary, and it's possible
// to save on ConcurrentSkipList size.
-template<typename NodeType, typename NodeAlloc>
+template <typename NodeType, typename NodeAlloc>
class NodeRecycler<NodeType, NodeAlloc, typename std::enable_if<
NodeType::template DestroyIsNoOp<NodeAlloc>::value>::type> {
public:
namespace folly {
-template<typename T,
- typename Comp = std::less<T>,
- // All nodes are allocated using provided SimpleAllocator,
- // it should be thread-safe.
- typename NodeAlloc = SysAlloc,
- int MAX_HEIGHT = 24>
+template <
+ typename T,
+ typename Comp = std::less<T>,
+ // All nodes are allocated using provided SimpleAllocator,
+ // it should be thread-safe.
+ typename NodeAlloc = SysAlloc,
+ int MAX_HEIGHT = 24>
class ConcurrentSkipList {
// MAX_HEIGHT needs to be at least 2 to suppress compiler
// warnings/errors (Werror=uninitialized tiggered due to preds_[1]
// list with the same key.
// pair.second stores whether the data is added successfully:
// 0 means not added, otherwise reutrns the new size.
- template<typename U>
+ template <typename U>
std::pair<NodeType*, size_t> addOrGetData(U &&data) {
NodeType *preds[MAX_HEIGHT], *succs[MAX_HEIGHT];
NodeType *newNode;
std::atomic<size_t> size_;
};
-template<typename T, typename Comp, typename NodeAlloc, int MAX_HEIGHT>
+template <typename T, typename Comp, typename NodeAlloc, int MAX_HEIGHT>
class ConcurrentSkipList<T, Comp, NodeAlloc, MAX_HEIGHT>::Accessor {
typedef detail::SkipListNode<T> NodeType;
typedef ConcurrentSkipList<T, Comp, NodeAlloc, MAX_HEIGHT> SkipListType;
const_iterator cbegin() const { return begin(); }
const_iterator cend() const { return end(); }
- template<typename U,
- typename=typename std::enable_if<std::is_convertible<U, T>::value>::type>
+ template <
+ typename U,
+ typename =
+ typename std::enable_if<std::is_convertible<U, T>::value>::type>
std::pair<iterator, bool> insert(U&& data) {
auto ret = sl_->addOrGetData(std::forward<U>(data));
return std::make_pair(iterator(ret.first), ret.second);
};
// implements forward iterator concept.
-template<typename ValT, typename NodeT>
+template <typename ValT, typename NodeT>
class detail::csl_iterator :
public boost::iterator_facade<csl_iterator<ValT, NodeT>,
ValT, boost::forward_traversal_tag> {
explicit csl_iterator(NodeT* node = nullptr) : node_(node) {}
- template<typename OtherVal, typename OtherNode>
+ template <typename OtherVal, typename OtherNode>
csl_iterator(const csl_iterator<OtherVal, OtherNode> &other,
typename std::enable_if<std::is_convertible<OtherVal, ValT>::value>::type*
= 0) : node_(other.node_) {}
private:
friend class boost::iterator_core_access;
- template<class,class> friend class csl_iterator;
+ template <class, class> friend class csl_iterator;
void increment() { node_ = node_->next(); }
bool equal(const csl_iterator& other) const { return node_ == other.node_; }
};
// Skipper interface
-template<typename T, typename Comp, typename NodeAlloc, int MAX_HEIGHT>
+template <typename T, typename Comp, typename NodeAlloc, int MAX_HEIGHT>
class ConcurrentSkipList<T, Comp, NodeAlloc, MAX_HEIGHT>::Skipper {
typedef detail::SkipListNode<T> NodeType;
typedef ConcurrentSkipList<T, Comp, NodeAlloc, MAX_HEIGHT> SkipListType;
*result += value;
}
-template<class T>
+template <class T>
constexpr typename std::enable_if<
std::is_same<T, char>::value,
size_t>::type
return 0;
}
-template<class Src>
+template <class Src>
typename std::enable_if<
(std::is_convertible<Src, folly::StringPiece>::value ||
IsSomeString<Src>::value) &&
return 0;
}
-template<class Src>
+template <class Src>
typename std::enable_if<
std::is_pointer<Src>::value &&
IsSomeString<std::remove_pointer<Src>>::value,
result->append(buffer + p, buffer + sizeof(buffer));
}
-template<class T>
+template <class T>
constexpr typename std::enable_if<
std::is_same<T, __int128>::value,
size_t>::type
return detail::digitsEnough<__int128>();
}
-template<class T>
+template <class T>
constexpr typename std::enable_if<
std::is_same<T, unsigned __int128>::value,
size_t>::type
* for estimateSpaceNeed for your type, so that we allocate
* as much as you need instead of the default
*/
-template<class Src>
+template <class Src>
struct HasLengthEstimator : std::false_type {};
template <class Src>
return estimateSpaceToReserve(sofar + estimateSpaceNeeded(v), vs...);
}
-template<class...Ts>
+template <class... Ts>
void reserveInTarget(const Ts&...vs) {
getLastElement(vs...)->reserve(estimateSpaceToReserve(0, vs...));
}
-template<class Delimiter, class...Ts>
+template <class Delimiter, class... Ts>
void reserveInTargetDelim(const Delimiter& d, const Ts&...vs) {
static_assert(sizeof...(vs) >= 2, "Needs at least 2 args");
size_t fordelim = (sizeof...(vs) - 2) *
namespace dynamicconverter_detail {
-template<typename T>
+template <typename T>
struct Dereferencer {
static inline void derefToCache(
Optional<T>* /* mem */,
}
};
-template<typename F, typename S>
+template <typename F, typename S>
struct Dereferencer<std::pair<F, S>> {
static inline void derefToCache(
Optional<std::pair<F, S>>* mem,
};
// pair
-template<typename A, typename B>
+template <typename A, typename B>
struct DynamicConstructor<std::pair<A, B>, void> {
static dynamic construct(const std::pair<A, B>& x) {
dynamic d = dynamic::array;
return DynamicConverter<typename std::remove_cv<T>::type>::convert(d);
}
-template<typename T>
+template <typename T>
dynamic toDynamic(const T& x) {
return DynamicConstructor<typename std::remove_cv<T>::type>::construct(x);
}
basic_fbstring& append(size_type n, value_type c);
- template<class InputIterator>
+ template <class InputIterator>
basic_fbstring& append(InputIterator first, InputIterator last) {
insert(end(), first, last);
return *this;
} // namespace hash
-template<class Key, class Enable = void>
+template <class Key, class Enable = void>
struct hasher;
struct Hash {
}
};
-template<> struct hasher<int32_t> {
+template <> struct hasher<int32_t> {
size_t operator()(int32_t key) const {
return hash::jenkins_rev_mix32(uint32_t(key));
}
};
-template<> struct hasher<uint32_t> {
+template <> struct hasher<uint32_t> {
size_t operator()(uint32_t key) const {
return hash::jenkins_rev_mix32(key);
}
};
-template<> struct hasher<int16_t> {
+template <> struct hasher<int16_t> {
size_t operator()(int16_t key) const {
return hasher<int32_t>()(key); // as impl accident, sign-extends
}
};
-template<> struct hasher<uint16_t> {
+template <> struct hasher<uint16_t> {
size_t operator()(uint16_t key) const {
return hasher<uint32_t>()(key);
}
};
-template<> struct hasher<int8_t> {
+template <> struct hasher<int8_t> {
size_t operator()(int8_t key) const {
return hasher<int32_t>()(key); // as impl accident, sign-extends
}
};
-template<> struct hasher<uint8_t> {
+template <> struct hasher<uint8_t> {
size_t operator()(uint8_t key) const {
return hasher<uint32_t>()(key);
}
};
-template<> struct hasher<char> {
+template <> struct hasher<char> {
using explicit_type =
std::conditional<std::is_signed<char>::value, int8_t, uint8_t>::type;
size_t operator()(char key) const {
}
};
-template<> struct hasher<int64_t> {
+template <> struct hasher<int64_t> {
size_t operator()(int64_t key) const {
return static_cast<size_t>(hash::twang_mix64(uint64_t(key)));
}
};
-template<> struct hasher<uint64_t> {
+template <> struct hasher<uint64_t> {
size_t operator()(uint64_t key) const {
return static_cast<size_t>(hash::twang_mix64(key));
}
};
-template<> struct hasher<std::string> {
+template <> struct hasher<std::string> {
size_t operator()(const std::string& key) const {
return static_cast<size_t>(
hash::SpookyHashV2::Hash64(key.data(), key.size(), 0));
} // folly
namespace std {
-template<>
+template <>
struct hash<folly::IPAddress> {
size_t operator()(const folly::IPAddress& addr) const {
return addr.hash();
} // folly
namespace std {
-template<>
+template <>
struct hash<folly::IPAddressV4> {
size_t operator()(const folly::IPAddressV4 addr) const {
return addr.hash();
} // folly
namespace std {
-template<>
+template <>
struct hash<folly::IPAddressV6> {
size_t operator()(const folly::IPAddressV6& addr) const {
return addr.hash();
* The elements stored in the list must contain an IntrusiveListHook member
* variable.
*/
-template<typename T, IntrusiveListHook T::* PtrToMember>
+template <typename T, IntrusiveListHook T::*PtrToMember>
using IntrusiveList = boost::intrusive::list<
T,
boost::intrusive::member_hook<T, IntrusiveListHook, PtrToMember>,
* The elements stored in the list must contain an SafeIntrusiveListHook member
* variable.
*/
-template<typename T, SafeIntrusiveListHook T::* PtrToMember>
+template <typename T, SafeIntrusiveListHook T::*PtrToMember>
using CountedIntrusiveList = boost::intrusive::list<
T,
boost::intrusive::member_hook<T, SafeIntrusiveListHook, PtrToMember>,
namespace detail {
-template<class Func>
+template <class Func>
struct Lazy {
typedef typename std::result_of<Func()>::type result_type;
//////////////////////////////////////////////////////////////////////
-template<class Func>
+template <class Func>
detail::Lazy<typename std::remove_reference<Func>::type>
lazy(Func&& fun) {
return detail::Lazy<typename std::remove_reference<Func>::type>(
namespace folly {
-template <template<typename> class Atom = std::atomic,
- class BatonType = Baton<Atom>>
+template <
+ template <typename> class Atom = std::atomic,
+ class BatonType = Baton<Atom>>
struct LifoSemImpl;
/// LifoSem is a semaphore that wakes its waiters in a manner intended to
/// LifoSemRawNode is the actual pooled storage that backs LifoSemNode
/// for user-specified Handoff types. This is done so that we can have
/// a large static IndexedMemPool of nodes, instead of per-type pools
-template <template<typename> class Atom>
+template <template <typename> class Atom>
struct LifoSemRawNode {
std::aligned_storage<sizeof(void*),alignof(void*)>::type raw;
/// If it has a wait() method then LifoSemBase's wait() implementation
/// will work out of the box, otherwise you will need to specialize
/// LifoSemBase::wait accordingly.
-template <typename Handoff, template<typename> class Atom>
+template <typename Handoff, template <typename> class Atom>
struct LifoSemNode : public LifoSemRawNode<Atom> {
static_assert(sizeof(Handoff) <= sizeof(LifoSemRawNode<Atom>::raw),
}
};
-template <typename Handoff, template<typename> class Atom>
+template <typename Handoff, template <typename> class Atom>
struct LifoSemNodeRecycler {
void operator()(LifoSemNode<Handoff,Atom>* elem) const {
elem->destroy();
///
/// The Handoff type is responsible for arranging one wakeup notification.
/// See LifoSemNode for more information on how to make your own.
-template <typename Handoff,
- template<typename> class Atom = std::atomic>
+template <typename Handoff, template <typename> class Atom = std::atomic>
struct LifoSemBase {
/// Constructor
} // namespace detail
-template <template<typename> class Atom, class BatonType>
+template <template <typename> class Atom, class BatonType>
struct LifoSemImpl : public detail::LifoSemBase<BatonType, Atom> {
constexpr explicit LifoSemImpl(uint32_t v = 0)
: detail::LifoSemBase<BatonType, Atom>(v) {}
namespace detail {
-template<typename T, template<typename> class Atom>
+template <typename T, template <typename> class Atom>
struct SingleElementQueue;
template <typename T> class MPMCPipelineStageImpl;
/// are you can enqueue one sentinel and then have each consumer requeue
/// two sentinels after it receives it (by requeuing 2 the shutdown can
/// complete in O(log P) time instead of O(P)).
-template<typename T, template<typename> class Atom = std::atomic,
- bool Dynamic = false>
+template <
+ typename T,
+ template <typename> class Atom = std::atomic,
+ bool Dynamic = false>
class MPMCQueue : public detail::MPMCQueueBase<MPMCQueue<T,Atom,Dynamic>> {
friend class detail::MPMCPipelineStageImpl<T>;
using Slot = detail::SingleElementQueue<T,Atom>;
///
/// The dynamic version is a partial specialization of MPMCQueue with
/// Dynamic == true
-template <typename T, template<typename> class Atom>
+template <typename T, template <typename> class Atom>
class MPMCQueue<T,Atom,true> :
public detail::MPMCQueueBase<MPMCQueue<T,Atom,true>> {
friend class detail::MPMCQueueBase<MPMCQueue<T,Atom,true>>;
namespace detail {
/// CRTP specialization of MPMCQueueBase
-template<
- template<
- typename T, template<typename> class Atom, bool Dynamic> class Derived,
- typename T, template<typename> class Atom, bool Dynamic>
+template <
+ template <typename T, template <typename> class Atom, bool Dynamic>
+ class Derived,
+ typename T,
+ template <typename> class Atom,
+ bool Dynamic>
class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable {
// Note: Using CRTP static casts in several functions of this base
#else
-template<typename T, typename... Args>
+template <typename T, typename... Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
// Allows 'make_unique<T[]>(10)'. (N3690 s20.9.1.4 p3-4)
-template<typename T>
+template <typename T>
typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(const size_t n) {
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]());
}
// Disallows 'make_unique<T[10]>()'. (N3690 s20.9.1.4 p5)
-template<typename T, typename... Args>
+template <typename T, typename... Args>
typename std::enable_if<
std::extent<T>::value != 0, std::unique_ptr<T>>::type
make_unique(Args&&...) = delete;
* A bitwise cast of the mapped bytes as range of values. Only intended for
* use with POD or in-place usable types.
*/
- template<class T>
+ template <class T>
Range<const T*> asRange() const {
size_t count = data_.size() / sizeof(T);
return Range<const T*>(static_cast<const T*>(
* A bitwise cast of the mapped bytes as range of mutable values. Only
* intended for use with POD or in-place usable types.
*/
- template<class T>
+ template <class T>
Range<T*> asWritableRange() const {
DCHECK(options_.writable); // you'll segfault anyway...
size_t count = data_.size() / sizeof(T);
namespace folly {
-template<class InputIt1, class InputIt2, class OutputIt, class Compare>
+template <class InputIt1, class InputIt2, class OutputIt, class Compare>
OutputIt merge(InputIt1 first1, InputIt1 last1,
InputIt2 first2, InputIt2 last2,
OutputIt d_first, Compare comp) {
return std::copy(first2, last2, d_first);
}
-template<class InputIt1, class InputIt2, class OutputIt>
+template <class InputIt1, class InputIt2, class OutputIt>
OutputIt merge(InputIt1 first1, InputIt1 last1,
InputIt2 first2, InputIt2 last2,
OutputIt d_first) {
namespace folly {
-template<class T>
+template <class T>
class PackedSyncPtr {
// This just allows using this class even with T=void. Attempting
// to use the operator* or operator[] on a PackedSyncPtr<void> will
* have a real constructor because we want this to be a POD type so we
* can put it into packed structs.
*/
-template<class IntType, int Bit = sizeof(IntType) * 8 - 1>
+template <class IntType, int Bit = sizeof(IntType) * 8 - 1>
struct PicoSpinLock {
// Internally we deal with the unsigned version of the type.
typedef typename std::make_unsigned<IntType>::type UIntType;
* ProducerConsumerQueue is a one producer and one consumer queue
* without locks.
*/
-template<class T>
+template <class T>
struct ProducerConsumerQueue {
typedef T value_type;
std::free(records_);
}
- template<class ...Args>
+ template <class... Args>
bool write(Args&&... recordArgs) {
auto const currentWrite = writeIndex_.load(std::memory_order_relaxed);
auto nextRecord = currentWrite + 1;
};
} // detail
-
-template<size_t kBitWidth, bool kFavorWriter=false>
+template <size_t kBitWidth, bool kFavorWriter = false>
class RWTicketSpinLockT {
typedef detail::RWTicketIntTrait<kBitWidth> IntTraitType;
typedef typename detail::RWTicketIntTrait<kBitWidth>::FullInt FullInt;
} ticket;
private: // Some x64-specific utilities for atomic access to ticket.
- template<class T> static T load_acquire(T* addr) {
+ template <class T> static T load_acquire(T* addr) {
T t = *addr; // acquire barrier
asm_volatile_memory();
return t;
}
- template<class T>
+ template <class T>
static void store_release(T* addr, T v) {
asm_volatile_memory();
*addr = v; // release barrier
StringPiece(needles));
}
-template<class Key, class Enable>
+template <class Key, class Enable>
struct hasher;
template <class T>
namespace std {
// Provide an implementation for std::hash<SocketAddress>
-template<>
+template <>
struct hash<folly::SocketAddress> {
size_t operator()(
const folly::SocketAddress& addr) const {
*
* @param ignoreEmpty iff true, don't copy empty segments to output
*/
-template<class OutStringT, class DelimT, class OutputIterator>
+template <class OutStringT, class DelimT, class OutputIterator>
void internalSplit(DelimT delim, StringPiece sp, OutputIterator out,
bool ignoreEmpty) {
assert(sp.empty() || sp.start() != nullptr);
}
}
-template<class String> StringPiece prepareDelim(const String& s) {
+template <class String> StringPiece prepareDelim(const String& s) {
return StringPiece(s);
}
inline char prepareDelim(char c) { return c; }
//////////////////////////////////////////////////////////////////////
-template<class Delim, class String, class OutputType>
+template <class Delim, class String, class OutputType>
void split(const Delim& delimiter,
const String& input,
std::vector<OutputType>& out,
ignoreEmpty);
}
-template<class Delim, class String, class OutputType>
+template <class Delim, class String, class OutputType>
void split(const Delim& delimiter,
const String& input,
fbvector<OutputType>& out,
ignoreEmpty);
}
-template<class OutputValueType, class Delim, class String,
- class OutputIterator>
+template <
+ class OutputValueType,
+ class Delim,
+ class String,
+ class OutputIterator>
void splitTo(const Delim& delimiter,
const String& input,
OutputIterator out,
}
}
-template<class InputString, class OutputString>
+template <class InputString, class OutputString>
bool hexlify(const InputString& input, OutputString& output,
bool append_output) {
if (!append_output) output.clear();
return true;
}
-template<class InputString, class OutputString>
+template <class InputString, class OutputString>
bool unhexlify(const InputString& input, OutputString& output) {
if (input.size() % 2 != 0) {
return false;
* If append_output is true, append data to the output rather than
* replace it.
*/
-template<class InputString, class OutputString>
+template <class InputString, class OutputString>
bool hexlify(const InputString& input, OutputString& output,
bool append=false);
* Same functionality as Python's binascii.unhexlify. Returns true
* on successful conversion.
*/
-template<class InputString, class OutputString>
+template <class InputString, class OutputString>
bool unhexlify(const InputString& input, OutputString& output);
template <class OutputString = std::string>
* or not (generating empty tokens).
*/
-template<class Delim, class String, class OutputType>
+template <class Delim, class String, class OutputType>
void split(const Delim& delimiter,
const String& input,
std::vector<OutputType>& out,
const bool ignoreEmpty = false);
-template<class Delim, class String, class OutputType>
+template <class Delim, class String, class OutputType>
void split(const Delim& delimiter,
const String& input,
folly::fbvector<OutputType>& out,
const bool ignoreEmpty = false);
-template<class OutputValueType, class Delim, class String,
- class OutputIterator>
+template <
+ class OutputValueType,
+ class Delim,
+ class String,
+ class OutputIterator>
void splitTo(const Delim& delimiter,
const String& input,
OutputIterator out,
* regular type, use it like this:
*
* // Make sure you're at namespace ::folly scope
- * template<> FOLLY_ASSUME_RELOCATABLE(MyType)
+ * template <> FOLLY_ASSUME_RELOCATABLE(MyType)
*
* When using it with a template type, use it like this:
*
* // Make sure you're at namespace ::folly scope
- * template<class T1, class T2>
+ * template <class T1, class T2>
* FOLLY_ASSUME_RELOCATABLE(MyType<T1, T2>)
*/
#define FOLLY_ASSUME_RELOCATABLE(...) \
}
};
-template<typename Allocator>
+template <typename Allocator>
struct GivesZeroFilledMemory : public std::false_type {};
-template<>
+template <>
struct GivesZeroFilledMemory<MMapAlloc> : public std::true_type{};
}}
namespace folly { namespace fileutil_detail {
// Wrap call to f(args) in loop to retry on EINTR
-template<class F, class... Args>
+template <class F, class... Args>
ssize_t wrapNoInt(F f, Args... args) {
ssize_t r;
do {
/* Available specializations, with definitions elsewhere */
-template<>
+template <>
int Futex<std::atomic>::futexWake(int count, uint32_t wakeMask);
-template<>
+template <>
FutexResult Futex<std::atomic>::futexWaitImpl(
uint32_t expected,
std::chrono::time_point<std::chrono::system_clock>* absSystemTime,
std::chrono::time_point<std::chrono::steady_clock>* absSteadyTime,
uint32_t waitMask);
-template<>
+template <>
int Futex<EmulatedFutexAtomic>::futexWake(int count, uint32_t wakeMask);
-template<>
+template <>
FutexResult Futex<EmulatedFutexAtomic>::futexWaitImpl(
uint32_t expected,
std::chrono::time_point<std::chrono::system_clock>* absSystemTime,
// gcc 4.7 doesn't do std::is_trivial correctly, override so we can use
// AtomicStruct<duration>
-template<>
+template <>
struct IsTriviallyCopyable<std::chrono::steady_clock::duration>
: std::true_type {};
/// cutoffs for different operations (read versus write, for example).
/// To avoid contention, the spin cutoff is only updated when requested
/// by the caller.
-template <template<typename> class Atom>
+template <template <typename> class Atom>
struct TurnSequencer {
explicit TurnSequencer(const uint32_t firstTurn = 0) noexcept
: state_(encode(firstTurn << kTurnShift, 0))
namespace std {
-template<>
-struct hash< ::folly::dynamic> {
+template <>
+struct hash<::folly::dynamic> {
size_t operator()(::folly::dynamic const& d) const {
return d.hash();
}
// This helper is used in destroy() to be able to run destructors on
// types like "int64_t" without a compiler error.
struct Destroy {
- template<class T> static void destroy(T* t) { t->~T(); }
+ template <class T> static void destroy(T* t) { t->~T(); }
};
/*
* numbers. Just promotes to double when one of the arguments is
* double, or throws if either is not a numeric type.
*/
- template<template<class> class Op>
+ template <template <class> class Op>
dynamic numericOp(dynamic const& a, dynamic const& b) {
if (!a.isNumber() || !b.isNumber()) {
throwTypeError_("numeric", a.type(), b.type());
using type = double;
};
-template<class T, class NumericType /* = typename NumericTypeHelper<T>::type */>
+template <
+ class T,
+ class NumericType /* = typename NumericTypeHelper<T>::type */>
dynamic::dynamic(T t) {
type_ = TypeInfo<NumericType>::type;
new (getAddress<NumericType>()) NumericType(NumericType(t));
return get<std::string>();
}
-template<class T>
+template <class T>
struct dynamic::CompareOp {
static bool comp(T const& a, T const& b) { return a < b; }
};
-template<>
+template <>
struct dynamic::CompareOp<dynamic::ObjectImpl> {
static bool comp(ObjectImpl const&, ObjectImpl const&) {
// This code never executes; it is just here for the compiler.
return false;
}
};
-template<>
+template <>
struct dynamic::CompareOp<std::nullptr_t> {
static bool comp(std::nullptr_t const&, std::nullptr_t const&) {
return true;
return std::move((*this)[idx]);
}
-template<class K, class V> inline dynamic& dynamic::setDefault(K&& k, V&& v) {
+template <class K, class V> inline dynamic& dynamic::setDefault(K&& k, V&& v) {
auto& obj = get<ObjectImpl>();
return obj.insert(std::make_pair(std::forward<K>(k),
std::forward<V>(v))).first->second;
}
-template<class K> inline dynamic& dynamic::setDefault(K&& k, dynamic&& v) {
+template <class K> inline dynamic& dynamic::setDefault(K&& k, dynamic&& v) {
auto& obj = get<ObjectImpl>();
return obj.insert(std::make_pair(std::forward<K>(k),
std::move(v))).first->second;
}
-template<class K> inline dynamic& dynamic::setDefault(K&& k, const dynamic& v) {
+template <class K> inline dynamic& dynamic::setDefault(K&& k, const dynamic& v) {
auto& obj = get<ObjectImpl>();
return obj.insert(std::make_pair(std::forward<K>(k), v)).first->second;
}
return get<ObjectImpl>().find(key);
}
-template<class K, class V> inline void dynamic::insert(K&& key, V&& val) {
+template <class K, class V> inline void dynamic::insert(K&& key, V&& val) {
auto& obj = get<ObjectImpl>();
auto rv = obj.insert({ std::forward<K>(key), nullptr });
rv.first->second = std::forward<V>(val);
#undef FOLLY_DYNAMIC_DEC_TYPEINFO
-template<class T>
+template <class T>
T dynamic::asImpl() const {
switch (type()) {
case INT64: return to<T>(*get_nothrow<int64_t>());
}
// Return a T* to our type, or null if we're not that type.
-template<class T>
+template <class T>
T* dynamic::get_nothrow() & noexcept {
if (type_ != TypeInfo<T>::type) {
return nullptr;
return getAddress<T>();
}
-template<class T>
+template <class T>
T const* dynamic::get_nothrow() const& noexcept {
return const_cast<dynamic*>(this)->get_nothrow<T>();
}
// Return T* for where we can put a T, without type checking. (Memory
// might be uninitialized, even.)
-template<class T>
+template <class T>
T* dynamic::getAddress() noexcept {
return GetAddrImpl<T>::get(u_);
}
-template<class T>
+template <class T>
T const* dynamic::getAddress() const noexcept {
return const_cast<dynamic*>(this)->getAddress<T>();
}
-template<class T> struct dynamic::GetAddrImpl {};
-template<> struct dynamic::GetAddrImpl<std::nullptr_t> {
+template <class T> struct dynamic::GetAddrImpl {};
+template <> struct dynamic::GetAddrImpl<std::nullptr_t> {
static std::nullptr_t* get(Data& d) noexcept { return &d.nul; }
};
-template<> struct dynamic::GetAddrImpl<dynamic::Array> {
+template <> struct dynamic::GetAddrImpl<dynamic::Array> {
static Array* get(Data& d) noexcept { return &d.array; }
};
-template<> struct dynamic::GetAddrImpl<bool> {
+template <> struct dynamic::GetAddrImpl<bool> {
static bool* get(Data& d) noexcept { return &d.boolean; }
};
-template<> struct dynamic::GetAddrImpl<int64_t> {
+template <> struct dynamic::GetAddrImpl<int64_t> {
static int64_t* get(Data& d) noexcept { return &d.integer; }
};
-template<> struct dynamic::GetAddrImpl<double> {
+template <> struct dynamic::GetAddrImpl<double> {
static double* get(Data& d) noexcept { return &d.doubl; }
};
template <>
return &d.string;
}
};
-template<> struct dynamic::GetAddrImpl<dynamic::ObjectImpl> {
+template <> struct dynamic::GetAddrImpl<dynamic::ObjectImpl> {
static_assert(sizeof(ObjectImpl) <= sizeof(Data::objectBuffer),
"In your implementation, std::unordered_map<> apparently takes different"
" amount of space depending on its template parameters. This is "
}
};
-template<class T>
+template <class T>
T& dynamic::get() {
if (auto* p = get_nothrow<T>()) {
return *p;
throwTypeError_(TypeInfo<T>::name, type());
}
-template<class T>
+template <class T>
T const& dynamic::get() const {
return const_cast<dynamic*>(this)->get<T>();
}
* Helper for implementing operator<<. Throws if the type shouldn't
* support it.
*/
-template<class T>
+template <class T>
struct dynamic::PrintImpl {
static void print(dynamic const&, std::ostream& out, T const& t) {
out << t;
out << "null";
}
};
-template<>
+template <>
struct dynamic::PrintImpl<dynamic::ObjectImpl> {
static void print(dynamic const& d,
std::ostream& out,
d.print_as_pseudo_json(out);
}
};
-template<>
+template <>
struct dynamic::PrintImpl<dynamic::Array> {
static void print(dynamic const& d,
std::ostream& out,
OBJECT,
STRING,
};
- template<class T, class Enable = void> struct NumericTypeHelper;
+ template <class T, class Enable = void> struct NumericTypeHelper;
/*
* We support direct iteration of arrays, and indirect iteration of objects.
* Constructors for integral and float types.
* Other types are SFINAEd out with NumericTypeHelper.
*/
- template<class T, class NumericType = typename NumericTypeHelper<T>::type>
+ template <class T, class NumericType = typename NumericTypeHelper<T>::type>
/* implicit */ dynamic(T t);
/*
* Create a dynamic that is an array of the values from the supplied
* iterator range.
*/
- template<class Iterator>
+ template <class Iterator>
explicit dynamic(Iterator first, Iterator last);
dynamic(dynamic const&);
dynamic getDefault(const dynamic& k, dynamic&& v) const&;
dynamic getDefault(const dynamic& k, const dynamic& v = dynamic::object) &&;
dynamic getDefault(const dynamic& k, dynamic&& v) &&;
- template<class K, class V>
+ template <class K, class V>
dynamic& setDefault(K&& k, V&& v);
// MSVC 2015 Update 3 needs these extra overloads because if V were a
// defaulted template parameter, it causes MSVC to consider v an rvalue
// reference rather than a universal reference, resulting in it not being
// able to find the correct overload to construct a dynamic with.
- template<class K>
+ template <class K>
dynamic& setDefault(K&& k, dynamic&& v);
- template<class K>
+ template <class K>
dynamic& setDefault(K&& k, const dynamic& v = dynamic::object);
/*
*
* Invalidates iterators.
*/
- template<class K, class V> void insert(K&&, V&& val);
+ template <class K, class V> void insert(K&&, V&& val);
/*
* These functions merge two folly dynamic objects.
private:
friend struct TypeError;
struct ObjectImpl;
- template<class T> struct TypeInfo;
- template<class T> struct CompareOp;
- template<class T> struct GetAddrImpl;
- template<class T> struct PrintImpl;
+ template <class T> struct TypeInfo;
+ template <class T> struct CompareOp;
+ template <class T> struct GetAddrImpl;
+ template <class T> struct PrintImpl;
explicit dynamic(Array&& array);
- template<class T> T const& get() const;
- template<class T> T& get();
- template<class T> T* get_nothrow() & noexcept;
- template<class T> T const* get_nothrow() const& noexcept;
- template<class T> T* get_nothrow() && noexcept = delete;
- template<class T> T* getAddress() noexcept;
- template<class T> T const* getAddress() const noexcept;
+ template <class T> T const& get() const;
+ template <class T> T& get();
+ template <class T> T* get_nothrow() & noexcept;
+ template <class T> T const* get_nothrow() const& noexcept;
+ template <class T> T* get_nothrow() && noexcept = delete;
+ template <class T> T* getAddress() noexcept;
+ template <class T> T const* getAddress() const noexcept;
- template<class T> T asImpl() const;
+ template <class T> T asImpl() const;
static char const* typeName(Type);
void destroy() noexcept;
namespace folly {
namespace detail {
-template<typename T,
- template<typename> class Atom>
+template <typename T, template <typename> class Atom>
class RingBufferSlot;
} // namespace detail
/// "future" can optionally block but reads from the "past" will always fail.
///
-template<typename T, template<typename> class Atom = std::atomic>
+template <typename T, template <typename> class Atom = std::atomic>
class LockFreeRingBuffer: boost::noncopyable {
static_assert(std::is_nothrow_default_constructible<T>::value,
}; // LockFreeRingBuffer
namespace detail {
-template<typename T, template<typename> class Atom>
+template <typename T, template <typename> class Atom>
class RingBufferSlot {
public:
explicit RingBufferSlot() noexcept
}
// expose the cursor raw value via a wrapper type
-template<typename T, template<typename> class Atom>
+template <typename T, template <typename> class Atom>
uint64_t value(const typename LockFreeRingBuffer<T, Atom>::Cursor& rbcursor) {
typedef typename LockFreeRingBuffer<T,Atom>::Cursor RBCursor;
return ExposedCursor(rbcursor).value();
}
-template<template<typename> class Atom>
+template <template <typename> class Atom>
void runReader(
LockFreeRingBuffer<int, Atom>& rb, std::atomic<int32_t>& writes
) {
}
}
-template<template<typename> class Atom>
+template <template <typename> class Atom>
void runWritesNeverFail(
int capacity, int writes, int writers
) {
#include <folly/experimental/RCURefCount.h>
#include <folly/portability/GFlags.h>
-template <template<typename> class MainPtr,
- template<typename> class WeakPtr,
- size_t threadCount>
+template <
+ template <typename> class MainPtr,
+ template <typename> class WeakPtr,
+ size_t threadCount>
void benchmark(size_t n) {
MainPtr<int> mainPtr(std::make_unique<int>(42));
template <class...> struct CollectVariadicContext;
template <class> struct CollectContext;
-template<typename F, typename... Args>
+template <typename F, typename... Args>
using resultOf = decltype(std::declval<F>()(std::declval<Args>()...));
template <typename...>
using Result = resultOf<F, Args...>;
};
-template<typename F, typename... Args>
+template <typename F, typename... Args>
struct callableWith {
- template<typename T,
- typename = detail::resultOf<T, Args...>>
+ template <typename T, typename = detail::resultOf<T, Args...>>
static constexpr std::true_type
check(std::nullptr_t) { return std::true_type{}; }
- template<typename>
+ template <typename>
static constexpr std::false_type
check(...) { return std::false_type{}; }
static constexpr bool value = type::value;
};
-template<typename T, typename F>
+template <typename T, typename F>
struct callableResult {
typedef typename std::conditional<
callableWith<F>::value,
/// first blush, but it's the same principle. In general, as long as the user
/// doesn't access a Future or Promise object from more than one thread at a
/// time there won't be any problems.
-template<typename T>
+template <typename T>
class Core final {
static_assert(!std::is_void<T>::value,
"void futures are not supported. Use Unit instead.");
Try<ItT>,
ItT>::type;
-template<typename F, typename T, typename Arg>
+template <typename F, typename T, typename Arg>
using isFutureResult = isFuture<typename std::result_of<F(T&&, Arg&&)>::type>;
/** repeatedly calls func on every result, e.g.
* Convenience class so that AsyncTransportWrapper can be decorated without
* having to redefine every single method.
*/
-template<class T>
+template <class T>
class DecoratedAsyncTransportWrapper : public folly::AsyncTransportWrapper {
public:
explicit DecoratedAsyncTransportWrapper(typename T::UniquePtr transport):
* by the get() method after set/erase is called. If shared ownership is
* needed, use a EventBaseLocal<shared_ptr<...>>.
*/
-template<typename T>
+template <typename T>
class EventBaseLocal : public detail::EventBaseLocalBase {
public:
EventBaseLocal(): EventBaseLocalBase() {}
* this moment in time. Locks a mutex so that these EventBase set cannot
* be changed, and also the caller can rely on no instances being destructed.
*/
- template<typename FunctionType>
+ template <typename FunctionType>
void withEventBaseSet(const FunctionType& runnable) {
// grab the mutex for the caller
std::lock_guard<std::mutex> g(*&eventBaseSetMutex_);
* spinning trying to move a message off the queue and failing, and then
* retrying.
*/
-template<typename MessageT>
+template <typename MessageT>
class NotificationQueue {
public:
/**
/**
* Put several messages on the queue.
*/
- template<typename InputIteratorT>
+ template <typename InputIteratorT>
void putMessages(InputIteratorT first, InputIteratorT last) {
typedef typename std::iterator_traits<InputIteratorT>::iterator_category
IterCategory;
return true;
}
- template<typename InputIteratorT>
+ template <typename InputIteratorT>
void putMessagesImpl(InputIteratorT first, InputIteratorT last,
std::input_iterator_tag) {
checkPid();
bool draining_{false};
};
-template<typename MessageT>
+template <typename MessageT>
void NotificationQueue<MessageT>::Consumer::destroy() {
// If we are in the middle of a call to handlerReady(), destroyedFlagPtr_
// will be non-nullptr. Mark the value that it points to, so that
DelayedDestruction::destroy();
}
-template<typename MessageT>
+template <typename MessageT>
void NotificationQueue<MessageT>::Consumer::handlerReady(uint16_t /*events*/)
noexcept {
consumeMessages(false);
}
-template<typename MessageT>
+template <typename MessageT>
void NotificationQueue<MessageT>::Consumer::consumeMessages(
bool isDrain, size_t* numConsumed) noexcept {
DestructorGuard dg(this);
}
}
-template<typename MessageT>
+template <typename MessageT>
void NotificationQueue<MessageT>::Consumer::init(
EventBase* eventBase,
NotificationQueue* queue) {
}
}
-template<typename MessageT>
+template <typename MessageT>
void NotificationQueue<MessageT>::Consumer::stopConsuming() {
if (queue_ == nullptr) {
assert(!isHandlerRegistered());
queue_ = nullptr;
}
-template<typename MessageT>
+template <typename MessageT>
bool NotificationQueue<MessageT>::Consumer::consumeUntilDrained(
size_t* numConsumed) noexcept {
DestructorGuard dg(this);
* destroy a UndelayedDestruction object while it has a non-zero destructor
* guard count will abort the program.
*/
-template<typename TDD>
+template <typename TDD>
class UndelayedDestruction : public TDD {
public:
// We could just use constructor inheritance, but not all compilers
// gcc code it looks like it has been fixed to return false. (The language
// in the standard seems to indicate that returning false is the correct
// behavior for non-destructible types, which is unfortunate.)
- template<typename ...Args>
+ template <typename... Args>
explicit UndelayedDestruction(Args&& ...args)
: TDD(std::forward<Args>(args)...) {
}
// Parse ahead for as long as the supplied predicate is satisfied,
// returning a range of what was skipped.
- template<class Predicate>
+ template <class Predicate>
StringPiece skipWhile(const Predicate& p) {
std::size_t skipped = 0;
for (; skipped < range_.size(); ++skipped) {
storeCurrent();
}
- template<class T>
+ template <class T>
T extract() {
try {
return to<T>(&range_);
//////////////////////////////////////////////////////////////////////
-template<class T, std::size_t M, class A, class B, class C>
+template <class T, std::size_t M, class A, class B, class C>
class small_vector;
//////////////////////////////////////////////////////////////////////
* Move a range to a range of uninitialized memory. Assumes the
* ranges don't overlap.
*/
- template<class T>
+ template <class T>
typename std::enable_if<
!FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
}
// Specialization for trivially copyable types.
- template<class T>
+ template <class T>
typename std::enable_if<
FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
* std::move_backward because move_backward only works if all the
* memory is initialized to type T already.
*/
- template<class T>
+ template <class T>
typename std::enable_if<
!FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
// Specialization for trivially copyable types. The call to
// std::move_backward here will just turn into a memmove. (TODO:
// change to std::is_trivially_copyable when that works.)
- template<class T>
+ template <class T>
typename std::enable_if<
FOLLY_IS_TRIVIALLY_COPYABLE(T)
>::type
* Populate a region of memory using `op' to construct elements. If
* anything throws, undo what we did.
*/
- template<class T, class Function>
+ template <class T, class Function>
void populateMemForward(T* mem, std::size_t n, Function const& op) {
std::size_t idx = 0;
try {
}
}
- template<class SizeType, bool ShouldUseHeap>
+ template <class SizeType, bool ShouldUseHeap>
struct IntegralSizePolicy {
typedef SizeType InternalSizeType;
* Apologies for all the black magic.
*/
namespace mpl = boost::mpl;
- template<class Value,
- std::size_t RequestedMaxInline,
- class InPolicyA,
- class InPolicyB,
- class InPolicyC>
+ template <
+ class Value,
+ std::size_t RequestedMaxInline,
+ class InPolicyA,
+ class InPolicyB,
+ class InPolicyC>
struct small_vector_base {
typedef mpl::vector<InPolicyA,InPolicyB,InPolicyC> PolicyList;
//////////////////////////////////////////////////////////////////////
FOLLY_PACK_PUSH
-template<class Value,
- std::size_t RequestedMaxInline = 1,
- class PolicyA = void,
- class PolicyB = void,
- class PolicyC = void>
+template <
+ class Value,
+ std::size_t RequestedMaxInline = 1,
+ class PolicyA = void,
+ class PolicyB = void,
+ class PolicyC = void>
class small_vector
: public detail::small_vector_base<
Value,RequestedMaxInline,PolicyA,PolicyB,PolicyC
doConstruct(n, [&](void* p) { new (p) value_type(t); });
}
- template<class Arg>
+ template <class Arg>
explicit small_vector(Arg arg1, Arg arg2) {
// Forward using std::is_arithmetic to get to the proper
// implementation; this disambiguates between the iterators and
return this->isExtern() ? u.heap() : u.buffer();
}
- template<class ...Args>
+ template <class... Args>
iterator emplace(const_iterator p, Args&&... args) {
if (p == cend()) {
emplace_back(std::forward<Args>(args)...);
return begin() + offset;
}
- template<class Arg>
+ template <class Arg>
iterator insert(const_iterator p, Arg arg1, Arg arg2) {
// Forward using std::is_arithmetic to get to the proper
// implementation; this disambiguates between the iterators and
erase(begin(), end());
}
- template<class Arg>
+ template <class Arg>
void assign(Arg first, Arg last) {
clear();
insert(end(), first, last);
// The std::false_type argument is part of disambiguating the
// iterator insert functions from integral types (see insert().)
- template<class It>
+ template <class It>
iterator insertImpl(iterator pos, It first, It last, std::false_type) {
typedef typename std::iterator_traits<It>::iterator_category categ;
if (std::is_same<categ,std::input_iterator_tag>::value) {
// The std::false_type argument came from std::is_arithmetic as part
// of disambiguating an overload (see the comment in the
// constructor).
- template<class It>
+ template <class It>
void constructImpl(It first, It last, std::false_type) {
typedef typename std::iterator_traits<It>::iterator_category categ;
if (std::is_same<categ,std::input_iterator_tag>::value) {
// Basic guarantee only, or provides the nothrow guarantee iff T has a
// nothrow move or copy constructor.
-template<class T, std::size_t MaxInline, class A, class B, class C>
+template <class T, std::size_t MaxInline, class A, class B, class C>
void swap(small_vector<T,MaxInline,A,B,C>& a,
small_vector<T,MaxInline,A,B,C>& b) {
a.swap(b);
* example growth policy that grows one element at a time:
*
* struct OneAtATimePolicy {
- * template<class Container>
+ * template <class Container>
* void increase_capacity(Container& c) {
* if (c.size() == c.capacity()) {
* c.reserve(c.size() + 1);
// This wrapper goes around a GrowthPolicy and provides iterator
// preservation semantics, but only if the growth policy is not the
// default (i.e. nothing).
- template<class Policy>
+ template <class Policy>
struct growth_policy_wrapper : private Policy {
- template<class Container, class Iterator>
+ template <class Container, class Iterator>
Iterator increase_capacity(Container& c, Iterator desired_insertion)
{
typedef typename Container::difference_type diff_t;
return c.begin() + d;
}
};
- template<>
+ template <>
struct growth_policy_wrapper<void> {
- template<class Container, class Iterator>
+ template <class Container, class Iterator>
Iterator increase_capacity(Container&, Iterator it) {
return it;
}
* (i.e. unless they are InputIterators). Otherwise this returns
* -1.
*/
- template<class Iterator>
+ template <class Iterator>
int distance_if_multipass(Iterator first, Iterator last) {
typedef typename std::iterator_traits<Iterator>::iterator_category categ;
if (std::is_same<categ,std::input_iterator_tag>::value)
return std::distance(first, last);
}
- template<class OurContainer, class Vector, class GrowthPolicy>
+ template <class OurContainer, class Vector, class GrowthPolicy>
typename OurContainer::iterator
insert_with_hint(OurContainer& sorted,
Vector& cont,
* @author Akhil Wable <akhil@fb.com>
* @author Jordan DeLong <delong.j@fb.com>
*/
-template<class T,
- class Compare = std::less<T>,
- class Allocator = std::allocator<T>,
- class GrowthPolicy = void>
+template <
+ class T,
+ class Compare = std::less<T>,
+ class Allocator = std::allocator<T>,
+ class GrowthPolicy = void>
class sorted_vector_set
: boost::totally_ordered1<
sorted_vector_set<T,Compare,Allocator,GrowthPolicy>
: m_(comp, alloc)
{}
- template<class InputIterator>
+ template <class InputIterator>
explicit sorted_vector_set(
InputIterator first,
InputIterator last,
get_growth_policy());
}
- template<class InputIterator>
+ template <class InputIterator>
void insert(InputIterator first, InputIterator last) {
detail::bulk_insert(*this, m_.cont_, first, last);
}
};
// Swap function that can be found using ADL.
-template<class T, class C, class A, class G>
+template <class T, class C, class A, class G>
inline void swap(sorted_vector_set<T,C,A,G>& a,
sorted_vector_set<T,C,A,G>& b) {
return a.swap(b);
* @author Akhil Wable <akhil@fb.com>
* @author Jordan DeLong <delong.j@fb.com>
*/
-template<class Key,
- class Value,
- class Compare = std::less<Key>,
- class Allocator = std::allocator<std::pair<Key,Value> >,
- class GrowthPolicy = void>
+template <
+ class Key,
+ class Value,
+ class Compare = std::less<Key>,
+ class Allocator = std::allocator<std::pair<Key, Value>>,
+ class GrowthPolicy = void>
class sorted_vector_map
: boost::totally_ordered1<
sorted_vector_map<Key,Value,Compare,Allocator,GrowthPolicy>
: m_(value_compare(comp), alloc)
{}
- template<class InputIterator>
+ template <class InputIterator>
explicit sorted_vector_map(
InputIterator first,
InputIterator last,
get_growth_policy());
}
- template<class InputIterator>
+ template <class InputIterator>
void insert(InputIterator first, InputIterator last) {
detail::bulk_insert(*this, m_.cont_, first, last);
}
};
// Swap function that can be found using ADL.
-template<class K, class V, class C, class A, class G>
+template <class K, class V, class C, class A, class G>
inline void swap(sorted_vector_map<K,V,C,A,G>& a,
sorted_vector_map<K,V,C,A,G>& b) {
return a.swap(b);
};
typedef GuardObjBase const& Guard;
-template<class F, class Tuple>
+template <class F, class Tuple>
struct GuardObj : GuardObjBase {
explicit GuardObj(F&& f, Tuple&& args)
: f_(std::forward<F>(f))
Tuple args_;
};
-template<class F, class ...Args>
+template <class F, class... Args>
GuardObj<typename std::decay<F>::type,std::tuple<Args...>>
guard(F&& f, Args&&... args) {
return GuardObj<typename std::decay<F>::type,std::tuple<Args...>>(
}
};
-template<typename Cmp>
+template <typename Cmp>
inline void test_operator_on_search(int iters) {
Cmp cmp;
int dummy = 0;
}
};
-template<class KeyT, class ValueT>
+template <class KeyT, class ValueT>
pair<KeyT,ValueT> createEntry(int i) {
return pair<KeyT,ValueT>(to<KeyT>(folly::hash::jenkins_rev_mix32(i) % 1000),
to<ValueT>(i + 3));
}
}
-template<class KeyT, class ValueT,
+template <
+ class KeyT,
+ class ValueT,
class Allocator = std::allocator<char>,
class ProbeFcn = AtomicHashArrayLinearProbeFcn>
void testNoncopyableMap() {
using namespace folly;
using namespace folly::test;
-template<class T>
+template <class T>
struct non_atomic {
T value;
EXPECT_TRUE(to<bool>(42ul));
}
-template<typename Src>
+template <typename Src>
void testStr2Bool() {
EXPECT_FALSE(to<bool>(Src("0")));
EXPECT_FALSE(to<bool>(Src(" 000 ")));
return lst;
}
-template<class T> T randomObject();
+template <class T> T randomObject();
-template<> int randomObject<int>() {
+template <> int randomObject<int>() {
return random(0, 1024);
}
-template<> folly::fbstring randomObject<folly::fbstring>() {
+template <> folly::fbstring randomObject<folly::fbstring>() {
folly::fbstring result;
randomString(&result);
return result;
str.resize(strlen(str.c_str()));
}
-template<class T> T randomObject();
+template <class T> T randomObject();
-template<> int randomObject<int>() {
+template <> int randomObject<int>() {
return random(0, 1024);
}
}
typedef DeterministicSchedule DSched;
-template <template<typename> class Atom>
+template <template <typename> class Atom>
void run_basic_thread(
Futex<Atom>& f) {
EXPECT_TRUE(f.futexWait(0));
}
-template <template<typename> class Atom>
+template <template <typename> class Atom>
void run_basic_tests() {
Futex<Atom> f(0);
DSched::join(thr);
}
-template <template<typename> class Atom, typename Clock, typename Duration>
+template <template <typename> class Atom, typename Clock, typename Duration>
void liveClockWaitUntilTests() {
Futex<Atom> f(0);
EXPECT_TRUE(res == FutexResult::TIMEDOUT || res == FutexResult::INTERRUPTED);
}
-template<template<typename> class Atom>
+template <template <typename> class Atom>
void run_wait_until_tests() {
liveClockWaitUntilTests<Atom, system_clock, system_clock::duration>();
liveClockWaitUntilTests<Atom, steady_clock, steady_clock::duration>();
typedef DeterministicSchedule DSched;
-template <template<typename> class Atom>
+template <template <typename> class Atom>
void run_mt_sequencer_thread(
int numThreads,
int numOps,
}
}
-template <template<typename> class Atom>
+template <template <typename> class Atom>
void run_mt_sequencer_test(int numThreads, int numOps, uint32_t init) {
TurnSequencer<Atom> seq(init);
Atom<uint32_t> spinThreshold(0);
}
}
-template <template<typename> class Atom, bool Dynamic = false>
+template <template <typename> class Atom, bool Dynamic = false>
void runTryEnqDeqThread(
int numThreads,
int n, /*numOps*/
sum += threadSum;
}
-template <template<typename> class Atom, bool Dynamic = false>
+template <template <typename> class Atom, bool Dynamic = false>
void runTryEnqDeqTest(int numThreads, int numOps) {
// write and read aren't linearizable, so we don't have
// hard guarantees on their individual behavior. We can still test
return nowMicro() - beginMicro;
}
-template <template<typename> class Atom, bool Dynamic = false>
+template <template <typename> class Atom, bool Dynamic = false>
void runMtNeverFail(std::vector<int>& nts, int n) {
for (int nt : nts) {
uint64_t elapsed = runNeverFailTest<Atom, Dynamic>(nt, n);
runMtNeverFail<EmulatedFutexAtomic>(nts, n);
}
-template<bool Dynamic = false>
+template <bool Dynamic = false>
void runMtNeverFailDeterministic(std::vector<int>& nts, int n, long seed) {
LOG(INFO) << "using seed " << seed;
for (int nt : nts) {
/// method signatures differ from the real Futex because we have elided
/// unused default params and collapsed templated methods into the
/// used type
-template<>
+template <>
struct Futex<MockAtom> {
MOCK_METHOD2(futexWait, bool(uint32_t, uint32_t));
MOCK_METHOD3(futexWaitUntil,
namespace folly {
-template<class V>
+template <class V>
std::ostream& operator<<(std::ostream& os, const Optional<V>& v) {
if (v) {
os << "Optional(" << v.value() << ')';
}
// Here we use the PackedSyncPtr to lock the whole SyncVec (base, *base, and sz)
-template<typename T>
+template <typename T>
struct SyncVec {
PackedSyncPtr<T> base;
SyncVec() { base.init(); }
typedef unsigned long LatencyType;
typedef ProducerConsumerQueue<LatencyType> LatencyQueueType;
-template<class QueueType>
+template <class QueueType>
struct ThroughputTest {
explicit ThroughputTest(size_t size, int iters, int cpu0, int cpu1)
: queue_(size),
int cpu1_;
};
-template<class QueueType>
+template <class QueueType>
struct LatencyTest {
explicit LatencyTest(size_t size, int iters, int cpu0, int cpu1)
: queue_(size),
namespace {
-template<class T> struct TestTraits {
+template <class T> struct TestTraits {
T limit() const { return 1 << 24; }
T generate() const { return rand() % 26; }
};
-template<> struct TestTraits<std::string> {
+template <> struct TestTraits<std::string> {
unsigned int limit() const { return 1 << 22; }
std::string generate() const { return std::string(12, ' '); }
};
-template<class QueueType, size_t Size, bool Pop = false>
+template <class QueueType, size_t Size, bool Pop = false>
struct PerfTest {
typedef typename QueueType::value_type T;
TestTraits<T> traits_;
};
-template<class TestType> void doTest(const char* name) {
+template <class TestType> void doTest(const char* name) {
LOG(INFO) << " testing: " << name;
std::unique_ptr<TestType> const t(new TestType());
(*t)();
}
-template<class T, bool Pop = false>
+template <class T, bool Pop = false>
void perfTestType(const char* type) {
const size_t size = 0xfffe;
"ProducerConsumerQueue");
}
-template<class QueueType, size_t Size, bool Pop>
+template <class QueueType, size_t Size, bool Pop>
struct CorrectnessTest {
typedef typename QueueType::value_type T;
std::atomic<bool> done_;
};
-template<class T, bool Pop = false>
+template <class T, bool Pop = false>
void correctnessTestType(const std::string& type) {
LOG(INFO) << "Type: " << type;
doTest<CorrectnessTest<folly::ProducerConsumerQueue<T>,0xfffe,Pop> >(
static std::atomic<bool> stopThread;
using namespace folly;
-template<typename RWSpinLockT> struct RWSpinLockTest: public testing::Test {
+template <typename RWSpinLockT> struct RWSpinLockTest: public testing::Test {
typedef RWSpinLockT RWSpinLockType;
};
TYPED_TEST_CASE(RWSpinLockTest, Implementations);
-template<typename RWSpinLockType>
+template <typename RWSpinLockType>
static void run(RWSpinLockType* lock) {
int64_t reads = 0;
int64_t writes = 0;
return &arr[0];
}
-template<class C>
+template <class C>
void testRangeFunc(C&& x, size_t n) {
const auto& cx = x;
// type, conversion checks
}
#ifdef FOLLY_PICO_SPIN_LOCK_H_
-template<class T> struct PslTest {
+template <class T> struct PslTest {
PicoSpinLock<T> lock;
PslTest() { lock.init(); }
}
};
-template<class T>
+template <class T>
void doPslTest() {
PslTest<T> testObj;
namespace {
-template<template<class,class> class VectorType>
+template <template <class, class> class VectorType>
void splitTest() {
VectorType<string,std::allocator<string> > parts;
EXPECT_EQ(parts[3], "");
}
-template<template<class,class> class VectorType>
+template <template <class, class> class VectorType>
void piecesTest() {
VectorType<StringPiece,std::allocator<StringPiece> > pieces;
VectorType<StringPiece,std::allocator<StringPiece> > pieces2;
return fds;
}
-template<class Runnable>
+template <class Runnable>
void checkFdLeak(const Runnable& r) {
// Get the currently open fds. Check that they are the same both before and
// after calling the specified function. We read the open fds from /proc.
// Invoke a function object as a template parameter.
// This can be used to directly invoke lambda functions
-template<typename T>
+template <typename T>
void BM_invoke_fn_template_impl(int iters, const T& fn) {
for (int n = 0; n < iters; ++n) {
fn();
throwCounter = 1000;
}
- template<class Operation>
+ template <class Operation>
void operator()(int insertCount, Operation const& op) {
bool done = false;
}
};
-template<class Container>
+template <class Container>
void check_invariant(Container& c) {
auto it = c.begin();
auto end = c.end();
}
struct OneAtATimePolicy {
- template<class Container>
+ template <class Container>
void increase_capacity(Container& c) {
if (c.size() == c.capacity()) {
c.reserve(c.size() + 1);