Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9089739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:12:48+00:00 2026-06-16T22:12:48+00:00

Consider the following code when a new container is defined over a std::array #include

  • 0

Consider the following code when a new container is defined over a std::array

#include <iostream>
#include <array>
#include <initializer_list>

// My container
template<typename Type, unsigned int Size>
class MyContainer
{
    // Lifecycle
    public:
        MyContainer() : _data() {}
        MyContainer(const MyContainer<Type, Size>& rhs) : _data(rhs.data()) {}
        MyContainer(const std::array<Type, Size>& rhs) : _data(rhs) {}
        template<typename... Types> MyContainer(const Types&... numbers) : _data({{numbers...}}) {}
        ~MyContainer() {}

    // Assignment
    public:
        MyContainer<Type, Size>& operator=(const MyContainer<Type, Size>& rhs) {_data = rhs.data(); return *this}

    // Accessors
    public:
        Type& operator[](const unsigned int i) {return _data[i];}
        const Type& operator[](const unsigned int i) const {return _data[i];}
        std::array<Type, Size>& data() {return _data;}
        const std::array<Type, Size>& data() const {return _data;}

    // Operators
    public:
        MyContainer<Type, Size> operator+(const MyContainer<Type, Size>& rhs)
        {
            MyContainer<Type, Size> result;
            for (unsigned int i = 0; i < Size; ++i) {
                result[i] = _data[i] + rhs[i];
            }
            return result;
        }

    // Data members
    protected:
        std::array<Type, Size> _data;
};

// Main
int main(int argc, char* argv[])
{
    // Initialization
    MyContainer<double, 4> x = {0., 1., 2., 3.};
    MyContainer<double, 4> y = {4., 5., 6., 7.};
    MyContainer<double, 4> z;

    // Operation
    z = x+y; // Can move semantics help here ?

    // Result
    std::cout<<z[0]<<" "<<z[1]<<" "<<z[2]<<" "<<z[3]<<std::endl;
    return 0;
}

Can move semantics speed up the operation in the main() by avoiding some copies ?

If the answer is yes, how to implement it in the current design ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:12:50+00:00Added an answer on June 16, 2026 at 10:12 pm

    No. All of the data of a std::array<double, N> is contained within the object itself. Move semantics only help when the object owns external referenced resources (usually via a pointer), and that reference can be copied and nullified.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: List<double> l = new List<double>(); //add unknown number of values
Consider the following arbitrary line of code: $object = new My_Object(); In Netbeans you
Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
Main question I'm trying to compile the following code with GCC 4.7.2: #include <iostream>
Consider the following code: 6. Set<Integer> set = new HashSet<Integer>(); 7. Integer i1 =
Consider following code: ArrayList<Integer> aList = new ArrayList<Integer>(); aList.add(2134); aList.add(3423); aList.add(4234); aList.add(343); String tmpString
Consider the following code: Dim arr1 As New List(Of Double) Dim arr2 As New
Consider the following code: using (var ms = new MemoryStream()) { using(var writer =
Consider the following code. var sParent:Sprite = new Sprite(); var obj:Sprite = new Sprite();
Consider following code: $acl = new Phalcon\Acl\Adapter\Memory(); $acl->setDefaultAction(Phalcon\Acl::DENY); //Register roles $acl->addRole(new Phalcon\Acl\Role('guest')); $acl->addRole(new Phalcon\Acl\Role('member',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.