#define vect std::vector - ok?
-
I am using
std::vector
in my project. Later on, however, this will change intocsr::vector
, a container defined in namespace csr that implements the same functions etc. I am writingstd::vector
everywhere in my code and I was wondering if I could do something like this#define vect std::vector
use
vect
in the code and change only the#define
when I have to switch tocsr
type of vector. Could this cause any issues?? -
I am using
std::vector
in my project. Later on, however, this will change intocsr::vector
, a container defined in namespace csr that implements the same functions etc. I am writingstd::vector
everywhere in my code and I was wondering if I could do something like this#define vect std::vector
use
vect
in the code and change only the#define
when I have to switch tocsr
type of vector. Could this cause any issues??You may also exploit the
using
directive for the purpose:using std::vector;
...
vector v;
...:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I am using
std::vector
in my project. Later on, however, this will change intocsr::vector
, a container defined in namespace csr that implements the same functions etc. I am writingstd::vector
everywhere in my code and I was wondering if I could do something like this#define vect std::vector
use
vect
in the code and change only the#define
when I have to switch tocsr
type of vector. Could this cause any issues??Hi, In your top level header (usually stdafx.h) switch the vector type:
// stdafx.h
//...
#ifdef USE_STD_VECTOR
#include <vector>
using std::vector;
#else
#include "csr_vector.h"
using csr::vector;
#endif
//...This allows you to set different Project Configurations in MS Visual Studio terminology: Win32 Std Debug, Win32 CSR Debug, etc ... differing by defining (or not)
USE_STD_VECTOR
at configuration level. cheers, ARWhen the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
-
I am using
std::vector
in my project. Later on, however, this will change intocsr::vector
, a container defined in namespace csr that implements the same functions etc. I am writingstd::vector
everywhere in my code and I was wondering if I could do something like this#define vect std::vector
use
vect
in the code and change only the#define
when I have to switch tocsr
type of vector. Could this cause any issues??If you're going to entirely replace
std::vector
withcsr::vector
you could simply usevector
everywhere instead ofstd::vector
. When including the header file you could then write -#include using namespace std;
Then when you're switching to the other namespace you simple change that to -
#include using namespace csr;
By the way, why are you planning to not use
std::vector
?«_Superman_» _I love work. It gives me something to do between weekends.
-
I am using
std::vector
in my project. Later on, however, this will change intocsr::vector
, a container defined in namespace csr that implements the same functions etc. I am writingstd::vector
everywhere in my code and I was wondering if I could do something like this#define vect std::vector
use
vect
in the code and change only the#define
when I have to switch tocsr
type of vector. Could this cause any issues??the other answers all speak about the use of "using", but you could use as well a typedef as in:
#ifdef USE_STD_VECTOR
typedef std::vector vector;
#else /* ! defined(USE_STD_VECTOR) */
typedef csr::vector vector;
#endif /* USE_STD_VECTOR */then everywhere you used std::vector you just use vector. Cheers