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

  • SEARCH
  • Home
  • 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 8871803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:04:54+00:00 2026-06-14T18:04:54+00:00

I’m working on testing whether or not my container wrappers are implementing URefs correctly.

  • 0

I’m working on testing whether or not my container wrappers are implementing URefs correctly. The only obvious way that I can think of is to try to figure out a way of detecting if an object has been moved.

Is there a good way of testing to make sure that an object was not copied? Or is there another way to test for what I want? I would prefer a solution that doesn’t require modifying the classes I’m testing. Because there’s a couple dozen of them.

Could you please provide some more info on what you have? Like what is your container, how you use it, can you modify it or not, etc. Maybe you can test this without modification of your container, but rather by using special container element type – which tracks copies and moves.

Several different containers and some standalone templated functions. Mostly, it’s wrappers around STL library types like deque, list, map, set, etc.

  • 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-14T18:04:54+00:00Added an answer on June 14, 2026 at 6:04 pm

    Is there a good way of testing to make sure that an object was not copied?

    You may try following check:

    live demo

    #include <boost/container/vector.hpp>
    #include <iostream>
    #include <ostream>
    #include <vector>
    #include <string>
    
    using namespace boost;
    using namespace std;
    
    struct Test
    {
        bool copied;
        Test()
            : copied(false)
        {
        }
        Test(const Test&)
            : copied(true)
        {
        }
    };
    
    template<typename Container>
    void check_move_constructor()
    {
        Container from(1);
        Container to(boost::move(from));
        cout << "\tmove constructor is" << (to[0].copied ? " not" : "") << " working" << endl;
    }
    
    template<typename Container>
    void check_move_assignment()
    {
        Container from(1);
        Container to;
        to=boost::move(from);
        cout << "\tmove assignment is" << (to[0].copied ? " not" : "") << " working" << endl;
    }
    
    template<typename Container>
    void check_move(const string &name)
    {
        cout << name << " :" << endl;
        check_move_constructor< Container >();
        check_move_assignment< Container >();
        cout << string(16,'_') << endl;
    }
    
    int main()
    {
        cout << boolalpha;
        check_move< container::vector<Test> >("boost::container::vector");
        check_move< vector<Test> >("std::vector");
        return 0;
    }
    

    MSVC2008 outputs:

    boost::container::vector :
            move constructor is working
            move assignment is working
    ________________
    std::vector :
            move constructor is not working
            move assignment is not working
    ________________
    

    Note, that in this code I used explicit move from lvalues, so Copy-elision can’t work here.







    P.S. another way to do this is to check generated assembler code. For instance /FA compiler option on MSVC or -S on GCC.

    You can mark place of interest with special function call:

    __declspec(noinline) void asm_marker(int line) { volatile int i=line; };
    #define ASM_MARKER asm_marker(__LINE__)
    

    And place that marker in code:

        ASM_MARKER;
        func_of_interest();
        ASM_MARKER;
    

    Asm code may look like:

        mov     ecx, 235                                ; 000000ebH
        call    ?asm_marker@@YAXH@Z                     ; asm_marker
        mov     edi, r12d
        lea     rcx, QWORD PTR [rdi+rdi*4]
        mov     rax, QWORD PTR vec$[rsp]
        lea     r9, QWORD PTR [rax+rcx*8]
        mov     rbx, QWORD PTR vec$[rsp+32]
        mov     ecx, 237                                ; 000000edH
        call    ?asm_marker@@YAXH@Z                     ; asm_marker   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported

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.