The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
ScalarTransformer.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
13#include "Transformer.h"
14
15namespace Gaudi::Functional {
16
17 // Scalar->Vector adapted N->1 algorithm
18 template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
20 template <typename ScalarOp, typename Out, typename... In, typename Traits_>
21 class ScalarTransformer<ScalarOp, Out( const In&... ), Traits_> : public Transformer<Out( const In&... ), Traits_> {
22
24 const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
25
26 public:
27 using Transformer<Out( const In&... ), Traits_>::Transformer;
28
30 Out operator()( const In&... in ) const override final {
31 const auto inrange = details::zip::range( in... );
32 Out out;
33 out.reserve( inrange.size() );
34 auto& scalar = scalarOp();
35 for ( const auto&& tuple : inrange ) {
38 [&out]( auto&& arg ) { details::insert( out, std::forward<decltype( arg )>( arg ) ); },
39 std::apply( [&]( const auto&... i ) { return scalar( details::deref( i )... ); }, tuple ) );
40 }
41 details::applyPostProcessing( scalar, out );
42 return out;
43 }
44 };
45
46 // Scalar->Vector adapted N->M algorithm
47 template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
49 template <typename ScalarOp, typename... Out, typename... In, typename Traits_>
50 class MultiScalarTransformer<ScalarOp, std::tuple<Out...>( const In&... ), Traits_>
51 : public MultiTransformer<std::tuple<Out...>( const In&... ), Traits_> {
52
54 const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
55
56 public:
57 using MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>::MultiTransformer;
58
60 std::tuple<Out...> operator()( const In&... in ) const override final {
61 const auto inrange = details::zip::range( in... );
62 std::tuple<Out...> out;
63 std::apply( [sz = inrange.size()]( auto&&... o ) { ( o.reserve( sz ), ... ); }, out );
64 auto& scalar = scalarOp();
65 for ( const auto&& indata : inrange ) {
66 std::apply(
67 [&scalar, &indata]( auto&... out ) {
72 [&out...]( auto&& outdata ) {
73 std::apply(
74 [&out...]( auto&&... outdata1 ) {
75 ( details::insert( out, std::forward<decltype( outdata1 )>( outdata1 ) ), ... );
76 },
77 std::forward<decltype( outdata )>( outdata ) );
78 },
79 std::apply( [&scalar]( const auto&... args ) { return scalar( details::deref( args )... ); },
80 indata ) );
81 },
82 out );
83 }
84 details::applyPostProcessing( scalar, out );
85 return out;
86 }
87 };
88} // namespace Gaudi::Functional
std::tuple< Out... > operator()(const In &... in) const override final
The main operator.
Out operator()(const In &... in) const override final
The main operator.
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition details.h:81
constexpr void applyPostProcessing(const Fun &, Container &, Args...)
Definition details.h:732
constexpr struct Gaudi::Functional::details::deref_t deref
constexpr struct Gaudi::Functional::details::insert_t insert
constexpr struct Gaudi::Functional::details::invoke_optionally_t invoke_optionally
STL namespace.