DBG with numbers

just a little idea here. i mean since DBG() is a very cpu intensive method anyway why not make it even worse and add the possibility to give it a bunch of numbers without wrapping String() around them all the time? :slight_smile: that could be pretty handy imo. image a method that takes an unspecific amount of numbers and automatically formats them like this in the output:

34545 :: 345.3434 :: 2323 :: 420.69

just by writing DBG( 34545, 345.3434, 2323, 420.69);

1 Like

It already supports the C++ streaming operator, so you can format your output like you want and you don’t need to construct Strings to use numbers :

DBG(34545 << " :: " << 345.3434 << " :: " << 2323 << " :: " << 420.69);
DBG("prepareToPlay(" << sampleRate << " , " << samplesPerBlock << ")");
1 Like

The problem with DBG is not the CPU, it is it needs asynchronous access to the console to print, so it is waiting for a lock on OS level. There is nothing that you can (or should bother) optimise.

…and after continuing to read… yeah, sure :joy: my bad

oh it does… is that new? when i started with juce (some weeks or months ago) i still had to use String() around all numbers in DBG. i already thought i had to figure out how to pass a variable number of arguments to a function to write my own printing method

You can use Variadic Templates to accomplish this formatting.
See this:

template<typename NumericType>
String formatNumbers(NumericType nt)
    return String(nt);

template<typename NumericType, typename ... Args>
String formatNumbers(NumericType nt, Args&& ... args)
    String out;
    out << formatNumbers(nt);
    out << " :: ";
    out << formatNumbers(args...);
    return out;

void test()
    DBG( formatNumbers( 3.14, 15, 1.9 ) );
1 Like

What I would find really handy is if you could do DBG(true). It’s a hassle having to write DBG(String(int(someBool))); over and over again.

@LiamG see DBG bool for a recent thread on that specific one.

1 Like