I was thinking of how I was going to create a robust versioning system in
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};
}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm... 11 2503
"Chris Thomasson" ,comp.lang.c++:
Anybody making good use out of namespace aliases?
Well, you can just use them for abbreviations; for instance, when using
Boost MPL library, it's quite common to write:
namespace mpl=boost:mpl;
"Pierre Senellart" <in*****@invalid.invalidwrote in message
news:et***********@nef.ens.fr...
"Chris Thomasson" ,comp.lang.c++:
>Anybody making good use out of namespace aliases?
Well, you can just use them for abbreviations; for instance, when using
Boost MPL library, it's quite common to write:
namespace mpl=boost:mpl;
what the difference between that and this:
namespace mpl {
using namespace boost::mpl;
}
?
I really don't see the main point of namespace aliases when we already have
the more flexible, IMHO, 'using namespace' keyword...
"Chris Thomasson" ,comp.lang.c++:
I really don't see the main point of namespace aliases when we already have
the more flexible, IMHO, 'using namespace' keyword...
I guess it is less powerful in the sense that you cannot add or override
things, but sometimes you just want to have an alias, nothing more, and
the namespace alias syntax is perfect for this role...
You could also argue in a similar way, that there is never a reason for
doing this :
typedef std::map<std::string,std::stringmap;
because you have a more powerful way to do this by using inheritance:
class map : public std::map<std::string,std::string{};
But here, the typedef is more appropriate because it makes the intent of
the programmer clear.
On Mar 13, 6:54 pm, "Chris Thomasson" <cris...@comcast.netwrote:
I was thinking of how I was going to create a robust versioning system in
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm...
As all of you, I used namespaces as it is. Never used aliases.
But in Effective C++ 3rd Edition, in the introduction section of C++
0x, Scott Meyers really explains the use of namespace aliases.
e.g In the case of C++ 0x, some of the TR1 components are taken from
Boost library. As the standard still under development and no compiler
available to test the new functionality of C++ 0x (heard that GNU C++
implemented some features of the proposed standard), we can't do some
samples and experiments. The components will be defined un TR1
namespace so that we can use componenents of boost namespaces as they
are in TR1 namespace. But still a question is really used by
somebody :_
On Mar 13, 5:54 pm, "Chris Thomasson" <cris...@comcast.netwrote:
I was thinking of how I was going to create a robust versioning system in
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm...
Namespaces are not only essential for me in C++, but also under
the .Net Framework; it simply makes my code readable and manages any
clashes of same names!!
Consider this header file:
#ifndef converterHPP
#define converterHPP
#include <sstream>
namespace convert
{
class string
{
public:
template <typename T>
static T to_number (const std::string& str)
{
T num;
std::istringstream str_s (str);
str_s >num;
return num;
}
};
class number
{
public:
template <typename T>
static std::string to_string (const T& num)
{
std::ostringstream o_str;
o_str << num;
return o_str.str();
}
};
}
#endif
It's up to me to name my namespace "convert", but I called one class
here "string" and it already exists in the standard c++ string
library!
In my code to execute, I could make the default namespace std and:
double d = 12342354.76658;
string str = convert::string<double>(d);
std::string versus convert::string; same class under two different
namespaces; it would have been a clash otherwise!
Don't you still see a use of this wonderful namespacing feature?!
On Mar 13, 5:54 pm, "Chris Thomasson" <cris...@comcast.netwrote:
I was thinking of how I was going to create a robust versioning system in
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm...
Namespaces are not only essential for me in C++, but also under
the .Net Framework; it simply makes my code readable and manages any
clashes of same names!!
Consider this header file:
#ifndef converterHPP
#define converterHPP
#include <sstream>
namespace convert
{
class string
{
public:
template <typename T>
static T to_number (const std::string& str)
{
T num;
std::istringstream str_s (str);
str_s >num;
return num;
}
};
class number
{
public:
template <typename T>
static std::string to_string (const T& num)
{
std::ostringstream o_str;
o_str << num;
return o_str.str();
}
};
}
#endif
It's up to me to name my namespace "convert", but I called one class
here "string" and it already exists in the standard c++ string
library!
In my code to execute, I could make the default namespace std and:
double d = 12342354.76658;
string str = convert::string<double>::to_number(d);
std::string versus convert::string; same class under two different
namespaces; it would have been a clash otherwise!
Don't you still see a use of this wonderful namespacing feature?!
On Mar 13, 5:54 pm, "Chris Thomasson" <cris...@comcast.netwrote:
I was thinking of how I was going to create a robust versioning system in
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm...
Namespaces are not only essential for me in C++, but also under
the .Net Framework; it simply makes my code readable and manages any
clashes of same names!!
Consider this header file:
#ifndef converterHPP
#define converterHPP
#include <sstream>
namespace convert
{
class string
{
public:
template <typename T>
static T to_number (const std::string& str)
{
T num;
std::istringstream str_s (str);
str_s >num;
return num;
}
};
class number
{
public:
template <typename T>
static std::string to_string (const T& num)
{
std::ostringstream o_str;
o_str << num;
return o_str.str();
}
};
}
#endif
It's up to me to name my namespace "convert", but I called one class
here "string" and it already exists in the standard c++ string
library!
In my code to execute, I could make the default namespace std and:
string str = "12342354.76658";
double d = convert::string<double>::to_number(str);
std::string versus convert::string; same class under two different
namespaces; it would have been a clash otherwise!
Don't you still see a use of this wonderful namespacing feature?!
coosa wrote:
On Mar 13, 5:54 pm, "Chris Thomasson" <cris...@comcast.netwrote:
>I was thinking of how I was going to create a robust versioning system in Standard C++ for my library and was wondering exactly what the point of a namespace alias is? The seem like a rather limited approach. For instance, you simply cannot "add-on" to a aliased namespace... Here is a quick example of what I am talking about:
__________________________ #include <stdio.h>
// version 1 of my library namespace mylib_version_1 { namespace constant { char const name[] = "My Library Version 1.0"; }
}
// version 1 of my library namespace mylib_version_2 { namespace constant { char const name[] = "My Library Version 2.0"; }
}
// method 1: create namespace alias to version 1 namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2 namespace mylib_using { using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!! // uncomment for error! // why can't you do this??? /* namespace mylib_alias { class something_extra { };}
*/
// add to namespace mylib_using namespace mylib_using { class something_extra { };
}
// entry int main() { printf("method 1: %s\n", mylib_alias::constant::name); printf("method 2: %s\n", mylib_using::constant::name); return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I would choose to use 'method 1' over 'method 2' in the implementation of my versioning system. Especially when you can't add to a namespace alias created with 'method 1'! I know I must be missing something here... Humm...
Namespaces are not only essential for me in C++, but also under
the .Net Framework; it simply makes my code readable and manages any
clashes of same names!!
Consider this header file:
#ifndef converterHPP
#define converterHPP
#include <sstream>
namespace convert
{
class string
{
public:
template <typename T>
static T to_number (const std::string& str)
{
T num;
std::istringstream str_s (str);
str_s >num;
return num;
}
};
class number
{
public:
template <typename T>
static std::string to_string (const T& num)
{
std::ostringstream o_str;
o_str << num;
return o_str.str();
}
};
}
#endif
It's up to me to name my namespace "convert", but I called one class
here "string" and it already exists in the standard c++ string
library!
In my code to execute, I could make the default namespace std and:
string str = "12342354.76658";
double d = convert::string<double>::to_number(str);
std::string versus convert::string; same class under two different
namespaces; it would have been a clash otherwise!
Don't you still see a use of this wonderful namespacing feature?!
He is talking about namespace aliases, not namespaces.
Also, why did you post 3 times the same message?
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[ http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
On Mar 17, 11:57 pm, Adrian Hawryluk <adrian.hawryluk-at-
gmail....@nospam.comwrote:
coosa wrote:
On Mar 13, 5:54 pm, "Chris Thomasson" <cris...@comcast.netwrote:
I was thinking of how I was going to create a robust versioning system in
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm...
Namespaces are not only essential for me in C++, but also under
the .Net Framework; it simply makes my code readable and manages any
clashes of same names!!
Consider this header file:
#ifndef converterHPP
#define converterHPP
#include <sstream>
namespace convert
{
class string
{
public:
template <typename T>
static T to_number (const std::string& str)
{
T num;
std::istringstream str_s (str);
str_s >num;
return num;
}
};
class number
{
public:
template <typename T>
static std::string to_string (const T& num)
{
std::ostringstream o_str;
o_str << num;
return o_str.str();
}
};
}
#endif
It's up to me to name my namespace "convert", but I called one class
here "string" and it already exists in the standard c++ string
library!
In my code to execute, I could make the default namespace std and:
string str = "12342354.76658";
double d = convert::string<double>::to_number(str);
std::string versus convert::string; same class under two different
namespaces; it would have been a clash otherwise!
Don't you still see a use of this wonderful namespacing feature?!
He is talking about namespace aliases, not namespaces.
Also, why did you post 3 times the same message?
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/...sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
I believe I deleted the previous two; sorry for the inconvenience
On Mar 13, 6:28 pm, Pierre Senellart <inva...@invalid.invalidwrote:
"Chris Thomasson" ,comp.lang.c++:
class map : public std::map<std::string,std::string{};
I was under the impression that you didn't get the constructors if you
did this? Do you not have to declare constructors and forward them to
the superclass or am I confused?
K
Kirit Sælensminde:
>class map : public std::map<std::string,std::string{};
I was under the impression that you didn't get the constructors if you
did this? Do you not have to declare constructors and forward them to
the superclass or am I confused?
Sure, unless you only need default and copy constructors. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: test1dellboy3 |
last post by:
Hi,
I am a beginner using the python interpreter. To reduce typing effort,
I created a module called "aliases.py" containing some aliases for
objects I commonly use like -
aliases.py :
...
|
by: |
last post by:
Hi,
Why do the 2.0 namespace aliases use the "::" notation where before the
namespaces used dot notation ".".
Ie.,
using IO = System.IO;
IO::Blah.Blah()..
|
by: Joe Bloggs |
last post by:
Hi,
I would like to programatically resolve aliases to the actual type,
eg. int to System.Int32.
Essentially, I would like to do this:
Type t = Type.GetType(ResolveAlias("int"));
if (t...
|
by: Chris Dunaway |
last post by:
The C# 3.0 spec (http://msdn.microsoft.com/vcsharp/future/) contains a
feature called "Implicitly typed local variables".
The type of the variable is determined at compile time based on the...
|
by: man |
last post by:
can any one please tell me what is the diff between pointer and
reference.....and which one is better to use ....and why???????
|
by: alex sparsky |
last post by:
I have a rather unique problem that I need some advice on.
I have multiple c# controls that need to make use of a common
namespace. So when I go to include both controls that make use of
that...
|
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...
|
by: segue |
last post by:
I have VS 2005, .NET 2.0, no girlfriend and this article:
http://msdn2.microsoft.com/en-us/library/ms278836.aspx.
Yet, I can't successfully import this namespace.
...
|
by: toton |
last post by:
Hi,
Is it possible to have a class level namespace opening instead of
file level .
Something like this,
I have a long namespace like
namespace com { namespace my_company{ namespace...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |