Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. #define vect std::vector - ok?

#define vect std::vector - ok?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdockerquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    piul
    wrote on last edited by
    #1

    I am using std::vector in my project. Later on, however, this will change into csr::vector, a container defined in namespace csr that implements the same functions etc. I am writing std::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 to csr type of vector. Could this cause any issues??

    C A _ F 4 Replies Last reply
    0
    • P piul

      I am using std::vector in my project. Later on, however, this will change into csr::vector, a container defined in namespace csr that implements the same functions etc. I am writing std::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 to csr type of vector. Could this cause any issues??

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      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]

      1 Reply Last reply
      0
      • P piul

        I am using std::vector in my project. Later on, however, this will change into csr::vector, a container defined in namespace csr that implements the same functions etc. I am writing std::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 to csr type of vector. Could this cause any issues??

        A Offline
        A Offline
        Alain Rist
        wrote on last edited by
        #3

        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, AR

        When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

        1 Reply Last reply
        0
        • P piul

          I am using std::vector in my project. Later on, however, this will change into csr::vector, a container defined in namespace csr that implements the same functions etc. I am writing std::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 to csr type of vector. Could this cause any issues??

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          If you're going to entirely replace std::vector with csr::vector you could simply use vector everywhere instead of std::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.

          _Microsoft MVP (Visual C++) Polymorphism in C

          1 Reply Last reply
          0
          • P piul

            I am using std::vector in my project. Later on, however, this will change into csr::vector, a container defined in namespace csr that implements the same functions etc. I am writing std::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 to csr type of vector. Could this cause any issues??

            F Offline
            F Offline
            federico strati
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups