c++ - how can returning a type instead of a object be valid, misunderstanding a code fragment -


i tried out boost msm lite nice state machine implementation. try understand how working , found code fragment can't understand.

as remark: not post whole file boost here, here: https://github.com/boost-experimental/msm-lite/blob/master/include/boost/msm-lite.hpp

the test code understanding things behind curtain:

 auto x2 = "test"_t;  //compiles fine! 

that should go code fragment:

 template <class t, t... chrs>  auto operator""_t() boost_msm_lite_noexcept {       return event<aux::string<chrs...>>;       // ??? how can work?  } 

my (mis)understanding here is, return type instead of instance of type? compiles... why?

event defined as:

template <class> struct event {      template <class t, boost_msm_lite_requires(concepts::callable<bool, t>::value)>         auto operator[](const t &t) const boost_msm_lite_noexcept {             return transition_eg<event, t>{*this, t};         }                                                                           template <class t, boost_msm_lite_requires(concepts::callable<void, t>::value)>         auto operator/(const t &t) const boost_msm_lite_noexcept {             return transition_ea<event, t>{*this, t};          }    }; 

the following example compiles fine:

#include <cassert> #include <iostream> #include "boost/msm-lite.hpp" namespace msm = boost::msm::lite;  int main() {     using namespace msm;     auto x1 = "idle"_s;     auto x2 = "test"_t; } 

template <class t, t... chrs> auto operator""_t() boost_msm_lite_noexcept {     return event<aux::string<chrs...>>;       // ??? how can work? } 

it works because operator not returning type, instance of template variable event, defined in line 1536:

template <class tevent> detail::event<tevent> event{}; 

template variables introduced in c++14, why harder find , understand. note _s operator relies on state, not template variable (thus why has instantiated @ operator function).


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -