3333#include < cassert>
3434#include < memory>
3535#include < type_traits>
36+ #include < concepts>
3637
3738#include < fairmq/FwdDecls.h>
3839
@@ -206,6 +207,28 @@ class InputRecord
206207 }
207208 return this ->getByPos (pos, part);
208209 }
210+
211+ template <typename R>
212+ requires std::is_convertible_v<R, char const *>
213+ DataRef getRef (R binding, int part = 0 ) const
214+ {
215+ return getDataRefByString (binding, part);
216+ }
217+
218+ template <typename R>
219+ requires requires (R r) { r.c_str (); }
220+ DataRef getRef (R binding, int part = 0 ) const
221+ {
222+ return getDataRefByString (binding.c_str (), part);
223+ }
224+
225+ template <typename R>
226+ requires std::is_convertible_v<R, DataRef>
227+ DataRef getRef (R ref, int part = 0 ) const
228+ {
229+ return ref;
230+ }
231+
209232 // / Get the object of specified type T for the binding R.
210233 // / If R is a string like object, we look up by name the InputSpec and
211234 // / return the data associated to the given label.
@@ -220,20 +243,7 @@ class InputRecord
220243 template <typename T = DataRef, typename R>
221244 decltype (auto ) get(R binding, int part = 0 ) const
222245 {
223- DataRef ref{nullptr , nullptr };
224- using decayed = std::decay_t <R>;
225-
226- // Get the actual dataref
227- if constexpr (std::is_same_v<decayed, char const *> ||
228- std::is_same_v<decayed, char *>) {
229- ref = getDataRefByString (binding, part);
230- } else if constexpr (std::is_same_v<decayed, std::string>) {
231- ref = getDataRefByString (binding.c_str (), part);
232- } else if constexpr (std::is_same_v<decayed, DataRef>) {
233- ref = binding;
234- } else {
235- static_assert (always_static_assert_v<R>, " Unknown binding type" );
236- }
246+ DataRef ref = getRef (binding, part);
237247
238248 using PointerLessValueT = std::remove_pointer_t <T>;
239249
0 commit comments