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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:15:07+00:00 2026-05-17T06:15:07+00:00

I am trying to implement a free operator function in order to stream values

  • 0

I am trying to implement a free operator function in order to stream values of arbitrary data type into some container class (DataVector).
I did a template for basic data types and some specializations for the complex data types used in my project (examples covers std::string only).
To make sure the template won’t be used with a data type which is not properly handled by the basic implementation, I want to restrict instatiation using type traits (is_integral). Several attempts embedding is_enabled is_integral into the signature of the operator failed and I ended up with the implementation show in the example below.

typedef std::vector<unsigned char> DataVector;

template<typename T>
DataVector& operator <<(DataVector& vecArchive, T dataToAppend)
{
    if (boost::is_integral<T>::value == true)
    {
        // ... do something
        return vecArchive;
    }
    BOOST_STATIC_ASSERT(false);
};

template<> inline
DataVector& operator << <string> (DataVector& vecArchive, string dataToAppend)
{
    // do something different
    return vecArchive;
};

The problem is that it won’t compile, even for integral data types. I guess BOOST_STATIC_ASSERT cannot be used in conditional expressions. How can it be done? Any help would be greatly appreciated.

main()
{
    DataVector vecTel;
    vecTel << (int)5;  // ok
    vecTel << std::string("Hello World");  // ok
    vecTel << std::map(int, int)  // must fail
}

Compiler error:

d:…\TcpSerializable.h(52) : error C2027: use of undefined type ‘boost::STATIC_ASSERTION_FAILURE’
with
[
x=false
]
.\Telegram050.cpp(38) : see reference to function template instantiation ‘BasisKlassen::DataVector &BasisKlassen::operator <<(BasisKlassen::DataVector &,T)’ being compiled
with
[
T=int
]

  • 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-05-17T06:15:08+00:00Added an answer on May 17, 2026 at 6:15 am

    I am no expert on boost, but from the look of it BOOST_STATIC_ASSERT(0) will compile even if the boost::is_integral<T>::value returns true (similar all other normal functions). Hence you get the compiler error (as intended when static assert’s condition returns false). To fix this, the simplest would be change the the function to something like:

    template<typename T>
    DataVector& operator <<(DataVector& vecArchive, T dataToAppend)
    {
        BOOST_STATIC_ASSERT(boost::is_integral<T>::value);
        // ... do something
        return vecArchive;
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying implement a most recent widget into my tumblr post. So far,
I trying to implement some relatively simple 2D sprite batching in OpenGL ES 2.0
I am trying to implement free-hand sketching (it should look like a pencil). I
I am trying to implement some tree like that in ASP.NET: alt text http://i.msdn.microsoft.com/w6ws38fw.vbVenusSiteNavigation_TreeView1(en-us,VS.100).gif
I am trying to implement face recognition on camera captured faces.In order to make
I'm trying to implement in app purchases in a free application. I have created
I am trying to implement some code to pick out the last line of
I'm trying to implement a stack structure in C, for storing char arrays into.
I am trying to implement caching in .Net such that the cached data is
I've been trying to implement unit testing and currently have some code that does

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.