FST  openfst-1.8.3
OpenFst Library
arg-packs.h
Go to the documentation of this file.
1 // Copyright 2005-2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 //
18 // std::pair and std::tuple are used for the arguments of FstClass operations.
19 //
20 // If a function with a return value is required, use the WithReturnValue
21 // template as follows:
22 //
23 // WithReturnValue<bool, std::tuple<...>>
24 
25 #ifndef FST_SCRIPT_ARG_PACKS_H_
26 #define FST_SCRIPT_ARG_PACKS_H_
27 
28 #include <type_traits>
29 
30 namespace fst {
31 namespace script {
32 
33 // Tack this on to an existing type to add a return value. The syntax for
34 // accessing the args is then slightly more stilted, as you must do an extra
35 // member access (since the args are stored as a member of this class).
36 
37 template <class Retval, class ArgTuple>
39  // Avoid reference-to-reference if ArgTuple is a reference.
40  using Args = std::remove_reference_t<ArgTuple>;
41 
42  Retval retval;
43  const Args &args;
44 
45  explicit WithReturnValue(const Args &args) : args(args) {}
46 };
47 
48 } // namespace script
49 } // namespace fst
50 
51 #endif // FST_SCRIPT_ARG_PACKS_H_
std::remove_reference_t< ArgTuple > Args
Definition: arg-packs.h:40
WithReturnValue(const Args &args)
Definition: arg-packs.h:45