// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include #include #ifndef CEPH_COMMON_BACKPORT14_H #define CEPH_COMMON_BACKPORT14_H // Library code from C++14 that can be implemented in C++11. namespace ceph { template using remove_extent_t = typename std::remove_extent::type; template using remove_reference_t = typename std::remove_reference::type; template using result_of_t = typename std::result_of::type; template using decay_t = typename std::decay::type; namespace _backport14 { template struct uniquity { using datum = std::unique_ptr; }; template struct uniquity { using array = std::unique_ptr; }; template struct uniquity { using verboten = void; }; template inline typename uniquity::datum make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } template inline typename uniquity::array make_unique(std::size_t n) { return std::unique_ptr(new remove_extent_t[n]()); } template typename uniquity::verboten make_unique(Args&&...) = delete; // The constexpr variant of std::max(). template constexpr const T& max(const T& a, const T& b) { return a < b ? b : a; } } // namespace _backport14 namespace _backport17 { template constexpr auto size(const C& c) -> decltype(c.size()) { return c.size(); } template constexpr std::size_t size(const T (&array)[N]) noexcept { return N; } /// http://en.cppreference.com/w/cpp/utility/functional/not_fn // this implementation uses c++14's result_of_t (above) instead of the c++17 // invoke_result_t, and so may not behave correctly when SFINAE is required template class not_fn_result { using DecayF = decay_t; DecayF fn; public: explicit not_fn_result(F&& f) : fn(std::forward(f)) {} not_fn_result(not_fn_result&& f) = default; not_fn_result(const not_fn_result& f) = default; template auto operator()(Args&&... args) & -> decltype(!std::declval>()) { return !fn(std::forward(args)...); } template auto operator()(Args&&... args) const& -> decltype(!std::declval>()) { return !fn(std::forward(args)...); } template auto operator()(Args&&... args) && -> decltype(!std::declval>()) { return !std::move(fn)(std::forward(args)...); } template auto operator()(Args&&... args) const&& -> decltype(!std::declval>()) { return !std::move(fn)(std::forward(args)...); } }; template not_fn_result not_fn(F&& fn) { return not_fn_result(std::forward(fn)); } } // namespace _backport17 using _backport14::make_unique; using _backport17::size; using _backport14::max; using _backport17::not_fn; } // namespace ceph #endif // CEPH_COMMON_BACKPORT14_H