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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:32:44+00:00 2026-05-11T01:32:44+00:00

I am using an application in c++ that uses a special dprintf function to

  • 0

I am using an application in c++ that uses a special dprintf function to print information, this is an example:

dprintf(verbose, 'The value is: %d', i); 

What is doing is when I define verbose for test purposes then I print the information and when I am working in normal execution I do not define it and I do not see useless information in the screen. My question is how can I do that function or implement the same idea?.

  • 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. 2026-05-11T01:32:45+00:00Added an answer on May 11, 2026 at 1:32 am

    I try to avoid using var-arg c-style functions for two main reasons:

    • They are not type-safe, can’t use operator<<
    • They don’t recognize when too few or many arguments were provided

    I’ve made a way that works using boost::fusion, which is given arguments in a type-safe way. It iterates over those arguments, printing out them when a % is encountered. If too few or too many arguments were given, an exception is thrown.

    There is one problem still: Variadic macros are not yet standard in C++. So, i have made two versions. One that work with current C++. You have to invoke it using

    dprintf('name: %, value: %\n', ('foo', 42)); 

    Then. The other version, using variadic macros, can be used by defining a preprocessor symbol, which enables you to write

    dprintf('name: %, value: %\n', 'foo', 42); 

    Here is the code. The boost.fusion provides more details for this:

    #include <boost/fusion/include/sequence.hpp> #include <boost/fusion/include/make_vector.hpp> #include <boost/fusion/include/next.hpp> #include <stdexcept> #include <iostream>  template<typename IterS, typename IterSeqE> void print_vec(IterS b, IterS e, IterSeqE, IterSeqE) {     while(b != e) {         if(*b == '%') {             if(++b != e && *b == '%') {                 std::cout << '%';             } else {                 throw std::invalid_argument('too many '%'');             }         } else {             std::cout << *b;         }         ++b;     } }  template<typename IterS, typename IterSeqB, typename IterSeqE> void print_vec(IterS b, IterS e, IterSeqB seqb, IterSeqE seqe) {     while(b != e) {         if(*b == '%') {             if(++b != e && *b == '%') {                 std::cout << '%';             } else {                 std::cout << *seqb;                 return print_vec(b, e, next(seqb), seqe);             }         } else {             std::cout << *b;         }         ++b;     }     throw std::invalid_argument('too few '%''); }  template<typename Seq> void print_vec(std::string const& msg, Seq const& seq) {     print_vec(msg.begin(), msg.end(), begin(seq), end(seq)); }  #ifdef USE_VARIADIC_MACRO #  ifdef DEBUG #    define dprintf(format, ...) \          print_vec(format, boost::fusion::make_vector(__VA_ARGS__)) #  else  #    define dprintf(format, ...) #  endif #else #  ifdef DEBUG #    define dprintf(format, args) \          print_vec(format, boost::fusion::make_vector args) #  else  #    define dprintf(format, args) #  endif #endif  // test, using the compatible version.  int main() {     dprintf('hello %, i'm % years old\n', ('litb', 22)); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Here's a solution which uses some LINQ plus dahlbyk's idea:… May 11, 2026 at 10:42 am
  • added an answer You need to write inside an element or give an… May 11, 2026 at 10:42 am
  • added an answer Easy: $db->quote($username); So: $username = $db->quote($username . '%'); $select =… May 11, 2026 at 10:42 am

Related Questions

I am using an application in c++ that uses a special dprintf function to
I am writing an application in Java using Swing. I am trying to implement
I am writing an application in Java for the desktop using the Eclipse SWT
I am using an Infragistics UltraGrid in a WinForms application. Which event is raised
I am using xml.net in web application When I try load xml through an
I am using a JEditorPane as an editor to write comments in my application.
I am using Infragistics UltraGrid in a Windows Forms application. I need an event
I am trying to process an uploaded file in a Perl program, using CGI::Application.
Currently I am using an ObservableCollection within a WPF application, the application is an
I am using asp.net mvc for an application. I've taken some guidance from Rob

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.