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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:39:01+00:00 2026-05-30T17:39:01+00:00

I was just trying to hack up a binary literal operator _b , but

  • 0

I was just trying to hack up a binary literal operator ""_b, but got stuck trying to terminate the recursion. How to define a function which can be called using an empty explicit template parameter list, which doesn’t conflict with a parameter pack overload? Then, inspiration: match the empty pack expansion to something wacky.

But GCC complains that the nonexistent types of the empty argument list don’t agree with not-explicitly-required types of the parameter list. Is it supposed to work this way?

template< char head, char ... tail >
constexpr unsigned long long parse_binary() {
    return ( ( head - '0' ) << sizeof ... (tail) )
        + parse_binary< tail ... >(); // Error: no overload for termination.
}

template< typename = void > // I want this to match an empty pack of chars.
// template< short = 0 > // even this would do.
constexpr unsigned long long parse_binary() {
    return 0;
}

template< char ... digits >
constexpr unsigned long long operator ""_b() {
    return parse_binary< digits ... >();
}

#include <iostream>

int main() {
    std::cout << 010101_b << '\n';
}

Note: The question isn’t implementing operator ""_b. That problem can be solved by expanding the pack into the parameter list, and passing std::integral_constant types around.

Note 2: This code actually does work with a minor adjustment; see my answer below. But that doesn’t directly address the question. Hmm, maybe I should have edited this instead of answering…

  • 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-30T17:39:02+00:00Added an answer on May 30, 2026 at 5:39 pm

    No official word on the compliance of such tricky matching, but the given code does work if the two overloads are transposed.

    The second, terminating overload is not visible to the first because the first resolves the name at template-definition time. Only function calls dependent on a template parameter have lookup deferred until instantiation time.

    Just to be clear, this works:

    template< typename = void > // Define this one first!
    constexpr unsigned long long parse_binary() {
        return 0;
    }
    
    template< char head, char ... tail >
    constexpr unsigned long long parse_binary() {
        return ( ( head - '0' ) << sizeof ... (tail) )
            + parse_binary< tail ... >(); // Bingo: overload found.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just trying to test for equality in this piece of code, but getting a
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas
Just trying to get my head around what can happen when things go wrong
I am trying to hack an old unix kernel. I just want to implement
I'm trying to hack together a datagridview in c# that can handle hierarchical data
I'm trying to create a CollapsiblePanel control, which is essentially just a panel which
I'm trying to create a small ffmpeg hack which enables parallel executin of the
Specifically I'm talking about Python. I'm trying to hack something (just a little) by
I'm trying to write a parser for the EDI data format, which is just
Just trying to get my head around Generics by reading this enlightening article by

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.