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 8312995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:20:54+00:00 2026-06-08T20:20:54+00:00

make_pair can create pairs without mentioning the types. I want to use the same

  • 0

make_pair can create pairs without mentioning the types. I want to use the same trick for my class, but it inherits from boost::noncopyable, so this does not compile:

template<class Iter>
struct bit_writer : boost:noncopyable
{
    Iter iter;
    bit_writer(Iter iter)
    : iter(iter)
    {}
};

template<class Iter>
bit_writer<Iter> make_bit_writer(Iter iter)
{
    return bit_writer<Iter>(iter);
}
vector<char> vec;
auto w = make_bit_writer(vec);

Any alternative? I tried making make_bit_writer a friend, and then run out of ideas.

  • 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-08T20:20:56+00:00Added an answer on June 8, 2026 at 8:20 pm

    If you have C++11 you can do this using something like:

    #include <functional>
    #include <utility>
    #include <type_traits>
    
    struct noncopyable_but_still_moveable {
      noncopyable_but_still_moveable(const noncopyable_but_still_moveable&) = delete;
      noncopyable_but_still_moveable(noncopyable_but_still_moveable&&) = default;
      noncopyable_but_still_moveable() = default;
      noncopyable_but_still_moveable& operator=(const noncopyable_but_still_moveable&) = default;
      noncopyable_but_still_moveable& operator=(noncopyable_but_still_moveable&&) = default;
    };
    
    template <typename T>
    struct test : noncopyable_but_still_moveable {
      test(T) {}
      // the rest is irrelevant 
    };
    
    template <typename T>
    test<T> make_test(T&& val) {
      return test<typename std::remove_reference<T>::type>(std::forward<T>(val));
    }
    
    int main() {
      auto && w = make_test(0);
    }
    

    Note that I’ve replaced boost::noncopyable with a type that has a deleted copy constructor. This is the C++11 way of making something non-copyable and is needed because the boost class was also not moveable. Of course you could just put that inside the class itself and not inherit any more.

    Without C++11 you’ll want to use something like Boost move to emulate these semantics.

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

Sidebar

Related Questions

I wrote this little code std::map<int,template<class T>> map_; map_.insert(make_pair<int,message>(myMsg.id,myMsg)); but the compiler doesn't seem
I need to create a list like List<String,Object> but I can't seem to do
i make one class file for jar. and this class have use wurfl. and
From http://fullthrottledevelopment.com/php-nonce-library#download , there is a PHP nonce library, but there are a few
For example: abstract class goal class priority class childgoal multimap<priority, goal> mm; mm.insert(make_pair(priority(), childgoal());
I don't understand why multimap exists if we can create map of vectors or
I have written a code in Python to create a transition probability matrix from
How can I store pairs of integers in a List? I know I could
In C++, you can use non-member getline() with a stream in a loop like
Suppose you want to take advantage of move semantics, but one of your movable

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.