c++ - build tuple from regex -


i have group of regexes , have map capture groups function arguments. seems me easiest thing build tuple regexes capture groups , use std::apply that. trying template convert regex tuple, not getting work. below have. tried specializing recursion, seems there no way specialize function template. new templating, welcome =)

template <size_t i> string get_value(std::smatch& rx) {     return rx[i]; }  template <size_t i> auto tuple_from_rx(std::smatch& rx) {     if (i > 0) {         return std::tuple_cat(tuple_from_rx<i -1>(rx), get_value<i>(rx));     }     else {         return std::tuple<>();     } } 

you may use following:

template <std::size_t ... is> auto as_tuple(const std::smatch& base_match, std::index_sequence<is...>) {     return make_tuple(std::string{base_match[1 + is]}...); }  template <std::size_t n> auto as_tuple(const std::smatch& base_match) {     return as_tuple(base_match, std::make_index_sequence<n>()); } 

problem implementation tuple_from_rx return different types. have use specialization instead:

template <size_t i> auto tuple_from_rx(std::smatch& rx) {     return std::tuple_cat(tuple_from_rx<i -1>(rx), std::make_tuple(get_value<i>(rx))); }  template <> auto tuple_from_rx<0u>(std::smatch&) {     return std::tuple<>(); } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -