473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What does this line of code mean?

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++?
Jan 19 '07 #1
5 1570

Bo Yang wrote:
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.

Jan 19 '07 #2
Bo Yang wrote:
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<Tobject 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.

Jan 19 '07 #3
Noah Roberts wrote:
>
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).

Jan 19 '07 #4
Bo Yang wrote:
<snip>
inline compose_f_gx_hx_t<0Pl,0P2,0P3>
<snip>
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.

Jan 19 '07 #5
David O :
Bo Yang wrote:
<snip>
>inline compose_f_gx_hx_t<0Pl,0P2,0P3>
<snip>
>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.
Thank you, I forget the function return type is a object.
Thank you!
Jan 20 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
6
by: Zhang Weiwu | last post by:
Hello. I am working with a php software project, in it (www.egroupware.org) Chinese simplified locate is "zh" while Traditional Chinese "tw". I wish to send correct language attribute in http...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
13
by: Protoman | last post by:
I'm getting an error: 10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i < (+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end ()' Code: Enigma.hpp...
3
by: qianz99 | last post by:
Hi I am not sure what this code does. I have the following questions 1. where is the case? 2. #define TLV_INTEGER(name, octets) p->name = -1; Is it define a function TLV_INTEGER(name, octets) ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.