Vc  1.2.0
SIMD Vector Classes for C++
is_functor_argument_immutable.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2014-2016 Matthias Kretz <kretz@kde.org>
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the names of contributing organizations nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 }}}*/
28 
29 #ifndef VC_TRAITS_IS_FUNCTOR_ARGUMENT_IMMUTABLE_H_
30 #define VC_TRAITS_IS_FUNCTOR_ARGUMENT_IMMUTABLE_H_
31 
32 namespace Vc_VERSIONED_NAMESPACE
33 {
34 namespace Traits
35 {
36 namespace is_functor_argument_immutable_impl
37 {
38 template <typename F, typename A> std::false_type test(void (F::*)(A &));
39 template <typename F, typename A> std::false_type test(void (F::*)(A &) const);
40 template <typename F, typename A> std:: true_type test(void (F::*)(const A &));
41 template <typename F, typename A> std:: true_type test(void (F::*)(const A &) const);
42 template <typename F, typename A> std:: true_type test(void (F::*)(const A &&));
43 template <typename F, typename A> std:: true_type test(void (F::*)(const A &&) const);
44 template <typename F, typename A> std:: true_type test(void (F::*)(const A));
45 template <typename F, typename A> std:: true_type test(void (F::*)(const A) const);
46 template <typename F, typename A> std:: true_type test(void (F::*)(A));
47 template <typename F, typename A> std:: true_type test(void (F::*)(A) const);
48 
49 // This function is defined with a forwarding reference. Therefore it can also bind as T
50 // &, in which case the argument is mutable.
51 template <typename F, typename A> std::false_type test(void (F::*)(A &&));
52 template <typename F, typename A> std::false_type test(void (F::*)(A &&) const);
53 
54 struct dummy {};
55 
56 // generate a true_type for template operator() members in F that are callable with a
57 // 'const A &' argument even if the template parameter to operator() is fixed to 'A'.
58 template <
59  typename F, typename A
60 #ifdef Vc_ICC
61  // this ensures that F is a generic lambda. We can be pretty sure that noone wrote a
62  // lambda with Vc::Traits::is_functor_argument_immutable_impl::dummy parameter
63  // type. In theory, this is not needed because the return type fails with a
64  // substitution failure in that case. Only ICC generates and error instead of doing
65  // SFINAE.
66  ,
67  typename = decltype(std::declval<F &>()(std::declval<dummy &>()))
68 #endif
69  ,
70  typename MemberPtr = decltype(&F::template operator()<A>)>
71 decltype(is_functor_argument_immutable_impl::test(std::declval<MemberPtr>())) test2(int);
72 
73 // generate a true_type for non-template operator() members in F that are callable with a
74 // 'const A &' argument.
75 template <typename F, typename A>
76 decltype(
77  is_functor_argument_immutable_impl::test(std::declval<decltype(&F::operator())>()))
78 test2(float);
79 
80 template <typename A> std::false_type test3(void (*)(A &));
81 template <typename A> std:: true_type test3(void (*)(const A &));
82 template <typename A> std:: true_type test3(void (*)(const A));
83 template <typename A> std:: true_type test3(void (*)(A));
84 template <typename A> std:: true_type test3(void (*)(A &&));
85 
86 } // namespace is_functor_argument_immutable_impl
87 
88 template <typename F, typename A, bool = std::is_function<F>::value>
89 struct is_functor_argument_immutable;
90 template <typename F, typename A>
91 struct is_functor_argument_immutable<F, A, false>
92  : public decltype(is_functor_argument_immutable_impl::test2<
93  typename std::remove_reference<F>::type, A>(int())) {
94 };
95 template <typename F, typename A>
96 struct is_functor_argument_immutable<F, A, true>
97  : public decltype(is_functor_argument_immutable_impl::test3(std::declval<F>())) {
98 };
99 
100 } // namespace Traits
101 } // namespace Vc
102 
103 #endif // VC_TRAITS_IS_FUNCTOR_ARGUMENT_IMMUTABLE_H_
104 
105 // vim: foldmethod=marker
Definition: vector.h:258