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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:15:06+00:00 2026-05-26T19:15:06+00:00

Is there an existing (in the standard library or in Boost) type trait to

  • 0

Is there an existing (in the standard library or in Boost) type trait to test whether a type could represent a string?

I stumbled upon an issue when using Boost.Fusion:

auto number = fusion::make_vector( 1, "one" );
auto numberName = fusion::filter< char const * >( number );

assert( numberName == fusion::make_vector( "one" ) ); // fails

I hoped filter would retain “one”, but it failed because “one” is not decayed to a pointer (make_vector takes its arguments by reference, so the type is const char (&)[4]). Consequently, I need a trait that would allow me to write something like this:

auto numberName = fusion::filter_if< is_string< mpl::_ > >( number );

I am aware that a char const * and a const char[N] are not necessarily null-terminated strings, but it would still be handy to be able to detect them uniformly. The trait could also possibly return true for std::string and the likes.

Does such a trait exist or will I have to write my own?

  • 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-26T19:15:06+00:00Added an answer on May 26, 2026 at 7:15 pm

    I gave a shot at implementing such a trait, but I am not sure it is really robust. Any input will be appreciated.

    template <typename T>
    struct is_string
        : public mpl::or_< // is "or_" included in the C++11 library?
            std::is_same<       char *, typename std::decay< T >::type >,
            std::is_same< const char *, typename std::decay< T >::type >
         > {};
    
    assert ( ! is_string< int >::value );
    
    assert (   is_string< char       *       >::value );
    assert (   is_string< char const *       >::value );
    assert (   is_string< char       * const >::value );
    assert (   is_string< char const * const >::value );
    
    assert (   is_string< char       (&)[5] >::value );
    assert (   is_string< char const (&)[5] >::value );
    
    // We could add specializations for string classes, e.g.
    template <>
    struct is_string<std::string> : std::true_type {};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some way through the standard library or some already existing library to
Is there an existing application or library in Java which will allow me to
Is there an existing PL/SQL method which takes a string and returns the same
In Haskell, Is there a standard library/package for generating Random / Arbitrary enums? I
Is there any PHP PDF library that can replace placeholder variables in an existing
Is there any javascript plugin/library/script that will can transform a standard PHP to use
I'm wondering if there is an existing class or library code in Cocoa Touch
Is there standard structure or library in C++ (or C++11) that is something like
Are there existing template extract libraries in either python or php? Perl has Template::Extract
Is there existing software for discriminative reranking, such as that used by the Charniak

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.