Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Best way to fill a maxon::BaseArray

    General Talk
    4
    6
    1.2k
    Loading More Posts
    • 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.
    • C4DSC
      C4DS
      last edited by

      Hi,
      Sometimes I feel like a C++ dinosaur.
      While the range-based for loop is available for quite a long time, I only discovered it a few years ago.
      Same for some other new and exciting stuff ...

      Probably known to many for a while (or longer), the following isn't yet set in stone into my aging memory.

      // example 1
      int myValues[] = { 1, 2, 3, 4 }; 
      
      // example 2
      std::vector<int> myValues = { 1, 2, 3, 4 };
      

      Quite like how these options can reduce code.
      Wondering how to initialize a maxon::BaseArray<> with known values, with least amount of code ?

      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by PluginStudent

        Example 1 is the initialization of a C-array from a brace-enclosed list.

        Example 2 is the construction of a std::vector object using an initializer list.

        So, does maxon::BaseArray has initializer list constructors or methods?

        Looking at the API, it seems it does not have such a constructor, but methods handling std::initializer_list. So you can actually write:

        maxon::BaseArray<maxon::Int> testArray;
        testArray.Append({ 1,2,3 }) iferr_return;
        
        1 Reply Last reply Reply Quote 2
        • r_giganteR
          r_gigante
          last edited by r_gigante

          Kudos to @PluginStudent saying in Best way to fill a maxon::BaseArray:

          maxon::BaseArraymaxon::Int testArray;
          testArray.Append({ 1,2,3 }) iferr_return;

          I confirm that only BaseArray::Append(), BaseArray::Insert() and BaseArray::Insert() can use an initialization list to add data to a BaseArray.

          Cheers, R

          C4DSC 1 Reply Last reply Reply Quote 1
          • C4DSC
            C4DS @r_gigante
            last edited by C4DS

            @PluginStudent
            @r_gigante
            Thanks for chipping in.

            If no more needs to be added I will set this as solved.

            1 Reply Last reply Reply Quote 0
            • fwilleke80F
              fwilleke80
              last edited by

              Just saw this thread...

              What if I want to fill the whole array with the same value?

              In Python this would be:

              arrayOfOnes = [1] * 10000
              

              Cheers,
              Frank

              www.frankwilleke.de
              Only asking personal code questions here.

              1 Reply Last reply Reply Quote 0
              • r_giganteR
                r_gigante
                last edited by r_gigante

                Unfortunately, differently from std lib where it's possible to define and init a vector pretty easily using one-line statement( std::vector<int> a (10, 100);) this looks like being not currently possible with maxon::BaseArray() and you need to make it the usual way.

                Best, R

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post