What does this line of code mean?

B

Bo Yang

Now, I am reading The C++ Standard Library,
there is one line of code which I can't understand.

template <class 0P1, class 0P2, class 0P3>
inline compose_f_gx_hx_t<0Pl,0P2,0P3>
compose_f_gx_hx (const 0P1& o1, const 0P2& o2, const 0P3& o3) {
return compose_f_gx_hx_t<0Pl,0P2,0P3>(ol,o2,o3);
}

I know what these code intended to do, but I can't understand the
syntax here!

the line begin with inline keyword, why is it there?
Is this syntax standard C++?
 
N

Noah Roberts

Bo said:
Now, I am reading The C++ Standard Library,
there is one line of code which I can't understand.

template <class 0P1, class 0P2, class 0P3>
inline compose_f_gx_hx_t<0Pl,0P2,0P3>
compose_f_gx_hx (const 0P1& o1, const 0P2& o2, const 0P3& o3) {
return compose_f_gx_hx_t<0Pl,0P2,0P3>(ol,o2,o3);
}

I know what these code intended to do, but I can't understand the
syntax here!

the line begin with inline keyword, why is it there?
Is this syntax standard C++?

Yes it is standard. It is there as a hint for the compiler to inline
that function. The function is a nicer constructor for a templated
class so that you can create one without having to specify the template
parameters.
 
D

David O

Bo said:
Now, I am reading The C++ Standard Library,
there is one line of code which I can't understand.

template <class 0P1, class 0P2, class 0P3>
inline compose_f_gx_hx_t<0Pl,0P2,0P3>
compose_f_gx_hx (const 0P1& o1, const 0P2& o2, const 0P3& o3) {
return compose_f_gx_hx_t<0Pl,0P2,0P3>(ol,o2,o3);
}

I know what these code intended to do, but I can't understand the
syntax here!

This declaration is comparable to:

template < class T > // for any type T
inline compose_type<T> // function return type
compose( T & t ) { // function parameters
return compose_type<T>( t ); // return from constructor
}

In other words compose<T>() simply constructs and returns an
compose_type<T> object for any type T. The code is obscured by having
three template parameters, OP1/2/3, intead of T, and having easily
confused names for the function and its result type - though knowing
that a "_t" conventionally implies a type makes it easier to scan.
the line begin with inline keyword, why is it there?

It's the return type.
Is this syntax standard C++?

Yes.

Best Regards,

David O.
 
R

Ron Natalie

Noah said:
Yes it is standard. It is there as a hint for the compiler to inline
that function. The function is a nicer constructor for a templated
class so that you can create one without having to specify the template
parameters.
It also allows that the function definition appear more than once (a
sort of precursor for most implementations to inline things).
 
D

David O

Bo Yang wrote:
inline compose_f_gx_hx_t<0Pl,0P2,0P3>
I know what these code intended to do, but I can't understand the
syntax here!

the line begin with inline keyword, why is it there?

Funny - I thought you were asking why the line "inline
compose_f_gx_hx_t<0Pl,0P2,0P3>" was there, rather than why the was
"inline" there! The other replies give excellent reasons for the
"inline" being present.

Another incidental benefit from its presence is that it assists human
scanning of complex template declarations telling the reader that
there's a function declaration lurking in there starting at the
"inline".

Best Regards,

David O.
 
B

Bo Yang

David O :
Bo Yang wrote:



Funny - I thought you were asking why the line "inline
compose_f_gx_hx_t<0Pl,0P2,0P3>" was there, rather than why the was
"inline" there! The other replies give excellent reasons for the
"inline" being present.

Another incidental benefit from its presence is that it assists human
scanning of complex template declarations telling the reader that
there's a function declaration lurking in there starting at the
"inline".

Best Regards,

David O.

Thank you, I forget the function return type is a object.
Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top