2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 * @brief This file is the header file of bind
25 * - Current implementation supports binding member functions (methods) only.
26 * - Currently up to 8 std::placeholders are supported.
27 * - Bound delegates are of type std::function<...>. This implies that
28 * passing arguments at bind-time is not supported (arguments MAY ONLY be
29 * passed at call-time).
32 * - For usage see tests/core/test_bind.cpp. In general, usage comes down to:
33 * std::function<ResultType(Args...)> delegate =
34 * DPL::Bind(&ObjectType::MethodName, &object);
42 #include <boost/preprocessor/cat.hpp>
43 #include <boost/preprocessor/arithmetic/add.hpp>
44 #include <boost/preprocessor/repetition/repeat.hpp>
49 struct PlaceholdersBindHelper;
51 #define DPL_PLACEHOLDERS_LIST_(z, n, t) ,BOOST_PP_CAT(std::placeholders::_, \
53 #define DPL_PLACEHOLDERS_(count) BOOST_PP_REPEAT(count, \
54 DPL_PLACEHOLDERS_LIST_, \
56 #define DPL_PLACEHOLDERS_BIND_HELPER_(count) \
58 struct PlaceholdersBindHelper<count> \
60 template<typename Result, typename Type, typename ...Args> \
61 static std::function<Result(Args...)> \
62 bind(Result(Type::*method)(Args...), Type* object) { \
63 return std::bind(method, object DPL_PLACEHOLDERS_(count)); \
67 DPL_PLACEHOLDERS_BIND_HELPER_(0);
68 DPL_PLACEHOLDERS_BIND_HELPER_(1);
69 DPL_PLACEHOLDERS_BIND_HELPER_(2);
70 DPL_PLACEHOLDERS_BIND_HELPER_(3);
71 DPL_PLACEHOLDERS_BIND_HELPER_(4);
72 DPL_PLACEHOLDERS_BIND_HELPER_(5);
73 DPL_PLACEHOLDERS_BIND_HELPER_(6);
74 DPL_PLACEHOLDERS_BIND_HELPER_(7);
75 DPL_PLACEHOLDERS_BIND_HELPER_(8);
78 template<typename Result, typename Type, typename ...Args>
79 std::function<Result(Args...)> Bind(Result(Type::*method)(Args...),
82 return detail::PlaceholdersBindHelper<sizeof...(Args)>::bind(method,