File indexing completed on 2025-01-26 05:06:09
0001 /* 0002 SPDX-FileCopyrightText: 2012 Ivan Cukic <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef UTILS_RANGE_H 0008 #define UTILS_RANGE_H 0009 0010 #include <boost/range/adaptor/filtered.hpp> 0011 #include <boost/range/adaptor/transformed.hpp> 0012 #include <boost/range/algorithm/copy.hpp> 0013 0014 /******************************************************************** 0015 * Syntactic sugar for converting ranges to collections * 0016 ********************************************************************/ 0017 0018 namespace kamd 0019 { 0020 namespace utils 0021 { 0022 template<typename Collection, typename Range> 0023 __inline Collection as_collection(Range range) 0024 { 0025 Collection result; 0026 0027 boost::copy(range, std::back_inserter(result)); 0028 0029 return result; 0030 } 0031 0032 template<typename Member, typename... Args> 0033 __inline auto transformed(Member member, Args... args) -> decltype(boost::adaptors::transformed(std::bind(member, args..., std::placeholders::_1))) 0034 { 0035 return boost::adaptors::transformed(std::bind(member, args..., std::placeholders::_1)); 0036 } 0037 0038 template<typename Member, typename... Args> 0039 __inline auto filtered(Member member, Args... args) -> decltype(boost::adaptors::filtered(std::bind(member, args..., std::placeholders::_1))) 0040 { 0041 return boost::adaptors::filtered(std::bind(member, args..., std::placeholders::_1)); 0042 } 0043 0044 template<typename Class, typename Member> 0045 __inline auto filtered(Class *const self, Member member) -> decltype(boost::adaptors::filtered(std::bind(member, self, std::placeholders::_1))) 0046 { 0047 return boost::adaptors::filtered(std::bind(member, self, std::placeholders::_1)); 0048 } 0049 0050 } // namespace utils 0051 } // namespace kamd 0052 0053 #endif // UTILS_RANGE_H