How can it return a type instead of an object, be valid, not understanding a piece of code

I tried raising msm lite, which is a very good implementation of the state machine. As always, I'm trying to figure out how this works, and I find a piece of code that I cannot understand.

As a note: I would not publish the entire file from boost here, here: https://github.com/boost-experimental/sml/blob/f636c05cb1a483e5131348d59d6151453ca3f9f2/include/boost/msm-lite.hpp

Test code just for understanding things behind the scenes:

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

This should go to this piece of code:

 template <class T, T... Chrs>
 auto operator""_t() BOOST_MSM_LITE_NOEXCEPT {
      return event<aux::string<Chrs...>>;       // ??? How this can work?
 }

My (wrong) understanding is that it will return typeinstead of a type instance? But it 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;
}
+4
1
template <class T, T... Chrs>
auto operator""_t() BOOST_MSM_LITE_NOEXCEPT {
    return event<aux::string<Chrs...>>;       // ??? How this can work?
}

, , event , 1536:

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

++ 14, . , _s state, ( ).

+7

Source: https://habr.com/ru/post/1653922/


All Articles