Using _t vs _type suffixes in typedefs

C

Chris Fairles

I'm wondering if theres any rationale behind using _t vs _type in
typedefs. I took a look in the standard and it doesn't say much
besides things like "size_type must be size_t", "difference_type must
be ptrdiff_t".

Looking at some libraries in Boost (Boost.GIL specifically) the
concepts describe types mainly using _type (value_type etc) but the
odd _t sneaks in there (const_t, layout_t).

One thing I notice is that _t is used more often with concrete types
whereas _type is used to re-declare template parameters etc. as its
something you usually want to pull out with scope resolution
(my_concrete_type<T>::value_type).

Any thoughts/opinions?

Cheers,
Chris
 
V

Victor Bazarov

Chris said:
I'm wondering if theres any rationale behind using _t vs _type in
typedefs. I took a look in the standard and it doesn't say much
besides things like "size_type must be size_t", "difference_type must
be ptrdiff_t".

I believe it's more of a nod in C direction. They use _t. 'size_t',
'ptrdiff_t', 'wchar_t' all are defined in C [as well]. It's easier
to have them named the same in the two related languages.

The C++ types that don't have counterparts in C (like 'size_type'
member of classes), don't have to be shortened.
Looking at some libraries in Boost (Boost.GIL specifically) the
concepts describe types mainly using _type (value_type etc) but the
odd _t sneaks in there (const_t, layout_t).

The 'value_type' typedef is part of the Standard containers.
One thing I notice is that _t is used more often with concrete types
whereas _type is used to re-declare template parameters etc. as its
something you usually want to pull out with scope resolution
(my_concrete_type<T>::value_type).

Any thoughts/opinions?

See above.

V
 
G

Gennaro Prota

Victor said:
The C++ types that don't have counterparts in C (like 'size_type'
member of classes), don't have to be shortened.

It's also worth noticing that *_t is reserved by POSIX.
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top