By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,407 Members | 2,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,407 IT Pros & Developers. It's quick & easy.

restrictions of std namespace

P: n/a
Hello,

I learned that we are not allowed to add any new templates or classes
or functions or anything else to std namespace. Does it mean that
"std" can never be extended? I can't even add any simple function or
class?

Thanks,
Jess

Jun 15 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Jess wrote:
Hello,

I learned that we are not allowed to add any new templates or classes
or functions or anything else to std namespace.
The rule is less strict. We're allowed to add any specialisations of
templates from 'std' _to_ 'std'.
Does it mean that
"std" can never be extended? I can't even add any simple function or
class?
Nothing simple. Only specialisations of standard templates.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 15 '07 #2

P: n/a
On Jun 15, 10:45 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Jess wrote:
Hello,
I learned that we are not allowed to add any new templates or classes
or functions or anything else to std namespace.

The rule is less strict. We're allowed to add any specialisations of
templates from 'std' _to_ 'std'.
Does it mean that
"std" can never be extended? I can't even add any simple function or
class?

Nothing simple. Only specialisations of standard templates.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Thanks! Also, does the specialized version have to be in the same
namespace as std? is it legal if i use another namespace or use global
namespace?

Thanks,
Jess

Jun 15 '07 #3

P: n/a
Jess wrote:
On Jun 15, 10:45 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Jess wrote:
>>Hello,
>>I learned that we are not allowed to add any new templates or
classes or functions or anything else to std namespace.

The rule is less strict. We're allowed to add any specialisations of
templates from 'std' _to_ 'std'.
>> Does it mean that
"std" can never be extended? I can't even add any simple function or
class?

Nothing simple. Only specialisations of standard templates.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Thanks! Also, does the specialized version have to be in the same
namespace as std?
Uh... "in the same namespace as std"? By "std" do you just mean "the
standard item it specialises"?
is it legal if i use another namespace or use global
namespace?
Yes, it's legal, as long as your compiler can find it when needed.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 15 '07 #4

P: n/a
I would like to ask two simple questions.

If you extend the std namespace how will you port your code to other
platform?

If you make changes to the std namespace how can others will port
their code to your machine?

Remember it's a **standard** and you are not a member of the standards
committee if you want to extend the std namespace try to become member
of the standards committee. Hope you will become that one day.

Jun 15 '07 #5

P: n/a
Amol wrote:
I would like to ask two simple questions.

If you extend the std namespace how will you port your code to other
platform?
Not sure what problem you are thinking of. Extending 'std' namespace
and portability are orthogonal. Your program will contain the 'std'
namespace extension, and since the contents of 'std' namespace are
essentially the same (the common denominator, anyway) on all platforms,
you just bring your extension to the target platform, and it should
compile without a problem.
If you make changes to the std namespace how can others will port
their code to your machine?
Again, if others have written portable programs, how would an extension
of 'std' namespace in _only one_ of your programs affect that?
Remember it's a **standard** and you are not a member of the standards
committee if you want to extend the std namespace try to become member
of the standards committee. Hope you will become that one day.
WTF are you talking about?

If I need to implement a specialisation of 'std::less' template for
my particular type (for whatever reason), I am _explicitly allowed_ to
do so by the Standard Committee. But the extend of my extension is
limited to my own code. I can share it with you, and then it becomes
part of your own code, and none of that affects anybody else who does
not add those extensions to their programs.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 15 '07 #6

P: n/a
"Jess" <wd***@hotmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
Hello,

I learned that we are not allowed to add any new templates or classes
or functions or anything else to std namespace. Does it mean that
"std" can never be extended? I can't even add any simple function or
class?
I think the reasoning behind this is that if you add some new template/class
to namespace std, then a new template/class gets added to the std namespace
in the next version that happens to have a name conflict with yours, your
code breaks. Which is what namespaces are trying to prevent in the first
place, name collisions.

I think the restriction is on adding new names into the std namespace that
may cause collisions. According to V extending templates and such is
allowed, but then you're not adding a *new* name are you?
Jun 16 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.