Skip to content

Commit bf485df

Browse files
committed
Revert "pass F (functor) by ref/const ref"
This reverts commit 2e0ce4a.
1 parent e031c53 commit bf485df

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

variant.hpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ struct unwrapper<std::reference_wrapper<T>>
258258
{
259259
return obj.get();
260260
}
261+
261262
};
262263

263264

@@ -268,7 +269,7 @@ template <typename F, typename V, typename R, typename T, typename...Types>
268269
struct dispatcher<F, V, R, T, Types...>
269270
{
270271
using result_type = R;
271-
VARIANT_INLINE static result_type apply_const(V const& v, F const& f)
272+
VARIANT_INLINE static result_type apply_const(V const& v, F f)
272273
{
273274
if (v.get_type_index() == sizeof...(Types))
274275
{
@@ -280,7 +281,7 @@ struct dispatcher<F, V, R, T, Types...>
280281
}
281282
}
282283

283-
VARIANT_INLINE static result_type apply(V & v, F & f)
284+
VARIANT_INLINE static result_type apply(V & v, F f)
284285
{
285286
if (v.get_type_index() == sizeof...(Types))
286287
{
@@ -297,12 +298,12 @@ template<typename F, typename V, typename R>
297298
struct dispatcher<F, V, R>
298299
{
299300
using result_type = R;
300-
VARIANT_INLINE static result_type apply_const(V const&, F const& f)
301+
VARIANT_INLINE static result_type apply_const(V const&, F)
301302
{
302303
throw std::runtime_error(std::string("unary dispatch: FAIL ") + typeid(V).name());
303304
}
304305

305-
VARIANT_INLINE static result_type apply(V &, F & f)
306+
VARIANT_INLINE static result_type apply(V &, F)
306307
{
307308
throw std::runtime_error(std::string("unary dispatch: FAIL ") + typeid(V).name());
308309
}
@@ -316,7 +317,7 @@ template <typename F, typename V, typename R, typename T0, typename T1, typename
316317
struct binary_dispatcher_rhs<F, V, R, T0, T1, Types...>
317318
{
318319
using result_type = R;
319-
VARIANT_INLINE static result_type apply_const(V const& lhs, V const& rhs, F const& f)
320+
VARIANT_INLINE static result_type apply_const(V const& lhs, V const& rhs, F f)
320321
{
321322
if (rhs.get_type_index() == sizeof...(Types)) // call binary functor
322323
{
@@ -329,7 +330,7 @@ struct binary_dispatcher_rhs<F, V, R, T0, T1, Types...>
329330
}
330331
}
331332

332-
VARIANT_INLINE static result_type apply(V & lhs, V & rhs, F & f)
333+
VARIANT_INLINE static result_type apply(V & lhs, V & rhs, F f)
333334
{
334335
if (rhs.get_type_index() == sizeof...(Types)) // call binary functor
335336
{
@@ -348,11 +349,11 @@ template<typename F, typename V, typename R, typename T>
348349
struct binary_dispatcher_rhs<F, V, R, T>
349350
{
350351
using result_type = R;
351-
VARIANT_INLINE static result_type apply_const(V const&, V const&, F const&)
352+
VARIANT_INLINE static result_type apply_const(V const&, V const&, F)
352353
{
353354
throw std::runtime_error("binary dispatch: FAIL");
354355
}
355-
VARIANT_INLINE static result_type apply(V &, V &, F &)
356+
VARIANT_INLINE static result_type apply(V &, V &, F)
356357
{
357358
throw std::runtime_error("binary dispatch: FAIL");
358359
}
@@ -366,7 +367,7 @@ template <typename F, typename V, typename R, typename T0, typename T1, typename
366367
struct binary_dispatcher_lhs<F, V, R, T0, T1, Types...>
367368
{
368369
using result_type = R;
369-
VARIANT_INLINE static result_type apply_const(V const& lhs, V const& rhs, F const& f)
370+
VARIANT_INLINE static result_type apply_const(V const& lhs, V const& rhs, F f)
370371
{
371372
if (lhs.get_type_index() == sizeof...(Types)) // call binary functor
372373
{
@@ -378,7 +379,7 @@ struct binary_dispatcher_lhs<F, V, R, T0, T1, Types...>
378379
}
379380
}
380381

381-
VARIANT_INLINE static result_type apply(V & lhs, V & rhs, F & f)
382+
VARIANT_INLINE static result_type apply(V & lhs, V & rhs, F f)
382383
{
383384
if (lhs.get_type_index() == sizeof...(Types)) // call binary functor
384385
{
@@ -396,12 +397,12 @@ template<typename F, typename V, typename R, typename T>
396397
struct binary_dispatcher_lhs<F, V, R, T>
397398
{
398399
using result_type = R;
399-
VARIANT_INLINE static result_type apply_const(V const&, V const&, F const&)
400+
VARIANT_INLINE static result_type apply_const(V const&, V const&, F)
400401
{
401402
throw std::runtime_error("binary dispatch: FAIL");
402403
}
403404

404-
VARIANT_INLINE static result_type apply(V &, V &, F &)
405+
VARIANT_INLINE static result_type apply(V &, V &, F)
405406
{
406407
throw std::runtime_error("binary dispatch: FAIL");
407408
}
@@ -414,7 +415,7 @@ template <typename F, typename V, typename R, typename T, typename...Types>
414415
struct binary_dispatcher<F, V, R, T, Types...>
415416
{
416417
using result_type = R;
417-
VARIANT_INLINE static result_type apply_const(V const& v0, V const& v1, F const& f)
418+
VARIANT_INLINE static result_type apply_const(V const& v0, V const& v1, F f)
418419
{
419420
if (v0.get_type_index() == sizeof...(Types))
420421
{
@@ -434,7 +435,7 @@ struct binary_dispatcher<F, V, R, T, Types...>
434435
return binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, f);
435436
}
436437

437-
VARIANT_INLINE static result_type apply(V & v0, V & v1, F & f)
438+
VARIANT_INLINE static result_type apply(V & v0, V & v1, F f)
438439
{
439440
if (v0.get_type_index() == sizeof...(Types))
440441
{
@@ -459,12 +460,12 @@ template<typename F, typename V, typename R>
459460
struct binary_dispatcher<F, V, R>
460461
{
461462
using result_type = R;
462-
VARIANT_INLINE static result_type apply_const(V const&, V const&, F const&)
463+
VARIANT_INLINE static result_type apply_const(V const&, V const&, F)
463464
{
464465
throw std::runtime_error("binary dispatch: FAIL");
465466
}
466467

467-
VARIANT_INLINE static result_type apply(V &, V &, F &)
468+
VARIANT_INLINE static result_type apply(V &, V &, F)
468469
{
469470
throw std::runtime_error("binary dispatch: FAIL");
470471
}
@@ -716,7 +717,7 @@ class variant
716717
// unary
717718
template <typename F, typename V>
718719
auto VARIANT_INLINE
719-
static visit(V const& v, F & f)
720+
static visit(V const& v, F f)
720721
-> decltype(detail::dispatcher<F, V,
721722
typename detail::result_of_unary_visit<F,
722723
typename detail::select_type<0, Types...>::type>::type, Types...>::apply_const(v, f))
@@ -727,7 +728,7 @@ class variant
727728
// non-const
728729
template <typename F, typename V>
729730
auto VARIANT_INLINE
730-
static visit(V & v, F & f)
731+
static visit(V & v, F f)
731732
-> decltype(detail::dispatcher<F, V,
732733
typename detail::result_of_unary_visit<F,
733734
typename detail::select_type<0, Types...>::type>::type, Types...>::apply(v, f))
@@ -740,7 +741,7 @@ class variant
740741
// const
741742
template <typename F, typename V>
742743
auto VARIANT_INLINE
743-
static binary_visit(V const& v0, V const& v1, F & f)
744+
static binary_visit(V const& v0, V const& v1, F f)
744745
-> decltype(detail::binary_dispatcher<F, V,
745746
typename detail::result_of_binary_visit<F,
746747
typename detail::select_type<0, Types...>::type>::type, Types...>::apply_const(v0, v1, f))
@@ -751,7 +752,7 @@ class variant
751752
// non-const
752753
template <typename F, typename V>
753754
auto VARIANT_INLINE
754-
static binary_visit(V& v0, V& v1, F & f)
755+
static binary_visit(V& v0, V& v1, F f)
755756
-> decltype(detail::binary_dispatcher<F, V,
756757
typename detail::result_of_binary_visit<F,
757758
typename detail::select_type<0, Types...>::type>::type, Types...>::apply(v0, v1, f))
@@ -791,27 +792,27 @@ class variant
791792

792793
// const
793794
template <typename V, typename F>
794-
auto VARIANT_INLINE static apply_visitor(F const& f, V const& v) -> decltype(V::visit(v, f))
795+
auto VARIANT_INLINE static apply_visitor(F f, V const& v) -> decltype(V::visit(v, f))
795796
{
796797
return V::visit(v, f);
797798
}
798799
// non-const
799800
template <typename V, typename F>
800-
auto VARIANT_INLINE static apply_visitor(F & f, V & v) -> decltype(V::visit(v, f))
801+
auto VARIANT_INLINE static apply_visitor(F f, V & v) -> decltype(V::visit(v, f))
801802
{
802803
return V::visit(v, f);
803804
}
804805

805806
// binary visitor interface
806807
// const
807808
template <typename V, typename F>
808-
auto VARIANT_INLINE static apply_visitor(F const& f, V const& v0, V const& v1) -> decltype(V::binary_visit(v0, v1, f))
809+
auto VARIANT_INLINE static apply_visitor(F f, V const& v0, V const& v1) -> decltype(V::binary_visit(v0, v1, f))
809810
{
810811
return V::binary_visit(v0, v1, f);
811812
}
812813
// non-const
813814
template <typename V, typename F>
814-
auto VARIANT_INLINE static apply_visitor(F & f, V & v0, V & v1) -> decltype(V::binary_visit(v0, v1, f))
815+
auto VARIANT_INLINE static apply_visitor(F f, V & v0, V & v1) -> decltype(V::binary_visit(v0, v1, f))
815816
{
816817
return V::binary_visit(v0, v1, f);
817818
}

0 commit comments

Comments
 (0)