You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

  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. #ifndef FST_SCRIPT_ARG_PACKS_H_
  25. #define FST_SCRIPT_ARG_PACKS_H_
  26. #include <type_traits>
  27. namespace fst {
  28. namespace script {
  29. // Tack this on to an existing type to add a return value. The syntax for
  30. // accessing the args is then slightly more stilted, as you must do an extra
  31. // member access (since the args are stored as a member of this class).
  32. template <class Retval, class ArgTuple>
  33. struct WithReturnValue {
  34. // Avoid reference-to-reference if ArgTuple is a reference.
  35. using Args = std::remove_reference_t<ArgTuple>;
  36. Retval retval;
  37. const Args &args;
  38. explicit WithReturnValue(const Args &args) : args(args) {}
  39. };
  40. } // namespace script
  41. } // namespace fst
  42. #endif // FST_SCRIPT_ARG_PACKS_H_