<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Schwachsinniger Code für Zwischendurch]]></title><description><![CDATA[<p>Hallo,<br />
ich habe mich heute mal wieder um meine echten Probleme rumgedrückt und stattdessen an einer Lösung für ein Problem gebastelt, das keins ist.</p>
<p>Ich hantiere an einigen Stellen in meinem Code mit ziemlich große Geldbeträgen.<br />
D.h. ich habe häufig sowas wie:<br />
Money price = 2000000000.0;<br />
oder:<br />
Money salary = 2000000.0;</p>
<p>Nun neige ich dazu mich bei den vielen Nullen zu vertippen, also wollte ich die magischen Zahlen durch symbolische Konstanten ersetzen. So in etwa:<br />
Money price = 2 Billion;</p>
<p>Die Syntax habe ich aber für kompliziertere Sachen (wie z.B. 2 Billion 3 Million) schon mal nicht hinbekommen. Aus irgendeinem für mich jetzt nicht mehr nachvollziehbarem Grund habe ich dann den ganzen Tag mit einer Templatelösung rumgespielt, die am Ende folgendes erlaubt:<br />
Money salary = !(2.0, Billion, 1.0, Million);<br />
bzw.<br />
Money salary = (2.0, Billion, 1.0, Million).eval();</p>
<p>Der Code sieht so aus:</p>
<pre><code class="language-cpp">#include &lt;assert.h&gt;
template &lt;bool&gt; struct StaticAssert;
template &lt;&gt; struct StaticAssert&lt;true&gt;{};

template &lt;class T&gt;
struct Multiplier
{
public:
	enum {id = T::id};
	double eval() const
	{
		return T::eval();
	}
};
struct Thousand_t
{
	enum {id = 0};
	static double eval()
	{
		return 1000.0;
	}
};
struct Million_t
{
	enum {id = 1};
	static double eval() { return 1000000.0; }
};
struct Billion_t
{
	enum {id = 2};
	static double eval() { return 1000000000.0; }
};
Multiplier&lt;Thousand_t&gt; Thousand;
Multiplier&lt;Million_t&gt; Million;
Multiplier&lt;Billion_t&gt; Billion;

class Value
{
public:
	explicit Value(double d) : value_(d)
	{}
	double eval() const
	{
		return value_;
	}
	double getValue() const
	{
		return value_;
	}
private:
	double value_;
};
template &lt;class Left, class Right&gt;
class Mult
{
public:
	Mult(Left l, Right r) : left_(l), right_(r) {}
	double eval() const
	{
		double left = left_.eval();
		double right = right_.eval();
		return left * right;
	}
	Left getLeft() const
	{
		return left_;
	}
	Right getRight() const
	{
		return right_;
	}
	typedef Left LeftType;
	typedef Right RightType;
private:
	Left left_;
	Right right_;
};

template &lt;class Left, class Right&gt;
class Add
{
public:
	Add(Left l, Right r) : left_(l), right_(r) {}
	double eval() const
	{
		double left = left_.eval();
		double right = right_.eval();
		return left + right;
	}
	Left getLeft() const
	{
		return left_;
	}
	Right getRight() const
	{
		return right_;
	}
	typedef Left LeftType;
	typedef Right RightType;
private:
	Left left_;
	Right right_;
};
template &lt;class T&gt;
struct GetMaxId
{
	typedef typename T::LeftType Left;
	typedef typename T::RightType Right;
	enum {
		maxId = GetMaxId&lt;Left&gt;::maxId &gt; 
				GetMaxId&lt;Right&gt;::maxId 
				? GetMaxId&lt;Left&gt;::maxId : GetMaxId&lt;Right&gt;::maxId
	};
};

template&lt;&gt;
struct GetMaxId&lt;Value&gt; { enum {maxId = -1}; };

template&lt;&gt;
struct GetMaxId&lt;Multiplier&lt;Billion_t&gt; &gt; { enum {maxId = Billion_t::id}; };

template&lt;&gt;
struct GetMaxId&lt;Multiplier&lt;Million_t&gt; &gt; { enum {maxId = Million_t::id}; };

template&lt;&gt;
struct GetMaxId&lt;Multiplier&lt;Thousand_t&gt; &gt; { enum {maxId = Thousand_t::id}; };

template &lt;class T&gt;
Add&lt;Mult&lt;Value, Multiplier&lt;T&gt; &gt;, Value&gt; operator,(double d, Multiplier&lt;T&gt; t)
{
	return Add&lt;Mult&lt;Value, Multiplier&lt;T&gt; &gt;, Value&gt;(
		Mult&lt;Value, Multiplier&lt;T&gt; &gt;(Value(d), t),
		Value(0)
	);
}

template &lt;class T&gt;
Add&lt;T, Value&gt; operator,(Add&lt;T, Value&gt; e, double z)
{
	return Add&lt;T, Value&gt;(e.getLeft(), Value(z));
}

template &lt;class T, class U&gt;
Add&lt;T, Mult&lt;Value, Multiplier&lt;U&gt; &gt; &gt;
operator,(Add&lt;T, Value&gt; e, Multiplier&lt;U&gt; m)
{
	{ 
		StaticAssert&lt;(GetMaxId&lt;T&gt;::maxId &gt; Multiplier&lt;U&gt;::id) &gt; ERROR_NOT_ALLOWED;
		(void)ERROR_NOT_ALLOWED;
	}
	double temp = e.getRight().getValue();
	return Add&lt;T, Mult&lt;Value, Multiplier&lt;U&gt; &gt; &gt;(e.getLeft(), 
		Mult&lt;Value, Multiplier&lt;U&gt; &gt;(Value(temp), m));
}

template &lt;class T, class U, class V&gt;
Add&lt;Add&lt;T, Mult&lt;U, V&gt; &gt;, Value&gt; operator,(Add&lt;T, Mult&lt;U, V&gt; &gt; e, double z)
{
	return Add&lt;Add&lt;T, Mult&lt;U, V&gt; &gt;, Value&gt;(e, Value(z));
}

template &lt;class T, class U&gt;
double operator!(Mult&lt;T, U&gt; m)
{
	return m.eval();
}
template &lt;class T, class U&gt;
double operator!(Add&lt;T, U&gt; m)
{
	return m.eval();
}

int main()
{
	double t1 = !(1.0,Thousand);	
	double m1 = !(1.0,Million);
	double b1 = (1,Billion).eval();
	assert(t1 == 1000.0);
	assert(m1 == 1000000.0);
	assert(b1 == 1000000000.0);

	double t2 = !(1.0,Thousand,100.0);	
	double m2 = !(1.0,Million,100.0);
	double b2 = !(1.0,Billion,100.0);
	assert(t2 == 1100.0);
	assert(m2 == 1000100.0);
	assert(b2 == 1000000100.0);

	double m3 = !(1.0,Million,1.0,Thousand);
	assert(m3 == 1001000.0);
	double m4 = !(1.0,Million,1.0,Thousand,1.0);
	assert(m4 == 1001001.0);

	double b3 = !(1.0,Billion,1.0,Thousand);
	assert(b3 == 1000001000.0);
	double b4 = !(1.0,Billion,1.0,Thousand,1.0);
	assert(b4 == 1000001001.0);
	double b5 = !(1.0,Billion,1.0,Million);
	assert(b5 == 1001000000.0);
	double b6 = !(1.0,Billion,1.0,Million,1.0);
	assert(b6 == 1001000001.0);

	double b7 = !(1.0,Billion,1.0,Million,1.0,Thousand);
	assert(b7 == 1001001000.0);

	double b8 = !(1.0,Billion,1.0,Million,1.0,Thousand,1.0);
	assert(b8 == 1001001001.0);

         // Wird korrekterweise als Fehlerhaft gemeldet:
        !(1.0,Billion, 1.0,Million, 1.0,Billion);
        !(1.0,Thousand,1.0,Million);
}
</code></pre>
<p>Er ist an einigen Stellen absichtlich etwas umständlicher, damit auch der VC 6.0 damit zurecht kommt (hier muss man allerdings einen anderen als den Komma-Operator verwenden. Z.B. operator|).</p>
<p>Warum belästige ich das Forum damit?<br />
Ganz einfach. Mir scheint ich habe mal wieder den schwachsinnigsten Weg gewählt und diesen möglichst kompliziert und inellegant implementiert.</p>
<p>Ich habe das sichere Gefühl, dass es eine viel einfachere und ellegantere Lösung gibt.<br />
Z.B. durch die geschickte Anwendung des Präprozessors.<br />
Würde mich also über Hinweise freuen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/46135/schwachsinniger-code-für-zwischendurch</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 14:29:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/46135.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 Aug 2003 22:37:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sat, 16 Aug 2003 22:37:38 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe mich heute mal wieder um meine echten Probleme rumgedrückt und stattdessen an einer Lösung für ein Problem gebastelt, das keins ist.</p>
<p>Ich hantiere an einigen Stellen in meinem Code mit ziemlich große Geldbeträgen.<br />
D.h. ich habe häufig sowas wie:<br />
Money price = 2000000000.0;<br />
oder:<br />
Money salary = 2000000.0;</p>
<p>Nun neige ich dazu mich bei den vielen Nullen zu vertippen, also wollte ich die magischen Zahlen durch symbolische Konstanten ersetzen. So in etwa:<br />
Money price = 2 Billion;</p>
<p>Die Syntax habe ich aber für kompliziertere Sachen (wie z.B. 2 Billion 3 Million) schon mal nicht hinbekommen. Aus irgendeinem für mich jetzt nicht mehr nachvollziehbarem Grund habe ich dann den ganzen Tag mit einer Templatelösung rumgespielt, die am Ende folgendes erlaubt:<br />
Money salary = !(2.0, Billion, 1.0, Million);<br />
bzw.<br />
Money salary = (2.0, Billion, 1.0, Million).eval();</p>
<p>Der Code sieht so aus:</p>
<pre><code class="language-cpp">#include &lt;assert.h&gt;
template &lt;bool&gt; struct StaticAssert;
template &lt;&gt; struct StaticAssert&lt;true&gt;{};

template &lt;class T&gt;
struct Multiplier
{
public:
	enum {id = T::id};
	double eval() const
	{
		return T::eval();
	}
};
struct Thousand_t
{
	enum {id = 0};
	static double eval()
	{
		return 1000.0;
	}
};
struct Million_t
{
	enum {id = 1};
	static double eval() { return 1000000.0; }
};
struct Billion_t
{
	enum {id = 2};
	static double eval() { return 1000000000.0; }
};
Multiplier&lt;Thousand_t&gt; Thousand;
Multiplier&lt;Million_t&gt; Million;
Multiplier&lt;Billion_t&gt; Billion;

class Value
{
public:
	explicit Value(double d) : value_(d)
	{}
	double eval() const
	{
		return value_;
	}
	double getValue() const
	{
		return value_;
	}
private:
	double value_;
};
template &lt;class Left, class Right&gt;
class Mult
{
public:
	Mult(Left l, Right r) : left_(l), right_(r) {}
	double eval() const
	{
		double left = left_.eval();
		double right = right_.eval();
		return left * right;
	}
	Left getLeft() const
	{
		return left_;
	}
	Right getRight() const
	{
		return right_;
	}
	typedef Left LeftType;
	typedef Right RightType;
private:
	Left left_;
	Right right_;
};

template &lt;class Left, class Right&gt;
class Add
{
public:
	Add(Left l, Right r) : left_(l), right_(r) {}
	double eval() const
	{
		double left = left_.eval();
		double right = right_.eval();
		return left + right;
	}
	Left getLeft() const
	{
		return left_;
	}
	Right getRight() const
	{
		return right_;
	}
	typedef Left LeftType;
	typedef Right RightType;
private:
	Left left_;
	Right right_;
};
template &lt;class T&gt;
struct GetMaxId
{
	typedef typename T::LeftType Left;
	typedef typename T::RightType Right;
	enum {
		maxId = GetMaxId&lt;Left&gt;::maxId &gt; 
				GetMaxId&lt;Right&gt;::maxId 
				? GetMaxId&lt;Left&gt;::maxId : GetMaxId&lt;Right&gt;::maxId
	};
};

template&lt;&gt;
struct GetMaxId&lt;Value&gt; { enum {maxId = -1}; };

template&lt;&gt;
struct GetMaxId&lt;Multiplier&lt;Billion_t&gt; &gt; { enum {maxId = Billion_t::id}; };

template&lt;&gt;
struct GetMaxId&lt;Multiplier&lt;Million_t&gt; &gt; { enum {maxId = Million_t::id}; };

template&lt;&gt;
struct GetMaxId&lt;Multiplier&lt;Thousand_t&gt; &gt; { enum {maxId = Thousand_t::id}; };

template &lt;class T&gt;
Add&lt;Mult&lt;Value, Multiplier&lt;T&gt; &gt;, Value&gt; operator,(double d, Multiplier&lt;T&gt; t)
{
	return Add&lt;Mult&lt;Value, Multiplier&lt;T&gt; &gt;, Value&gt;(
		Mult&lt;Value, Multiplier&lt;T&gt; &gt;(Value(d), t),
		Value(0)
	);
}

template &lt;class T&gt;
Add&lt;T, Value&gt; operator,(Add&lt;T, Value&gt; e, double z)
{
	return Add&lt;T, Value&gt;(e.getLeft(), Value(z));
}

template &lt;class T, class U&gt;
Add&lt;T, Mult&lt;Value, Multiplier&lt;U&gt; &gt; &gt;
operator,(Add&lt;T, Value&gt; e, Multiplier&lt;U&gt; m)
{
	{ 
		StaticAssert&lt;(GetMaxId&lt;T&gt;::maxId &gt; Multiplier&lt;U&gt;::id) &gt; ERROR_NOT_ALLOWED;
		(void)ERROR_NOT_ALLOWED;
	}
	double temp = e.getRight().getValue();
	return Add&lt;T, Mult&lt;Value, Multiplier&lt;U&gt; &gt; &gt;(e.getLeft(), 
		Mult&lt;Value, Multiplier&lt;U&gt; &gt;(Value(temp), m));
}

template &lt;class T, class U, class V&gt;
Add&lt;Add&lt;T, Mult&lt;U, V&gt; &gt;, Value&gt; operator,(Add&lt;T, Mult&lt;U, V&gt; &gt; e, double z)
{
	return Add&lt;Add&lt;T, Mult&lt;U, V&gt; &gt;, Value&gt;(e, Value(z));
}

template &lt;class T, class U&gt;
double operator!(Mult&lt;T, U&gt; m)
{
	return m.eval();
}
template &lt;class T, class U&gt;
double operator!(Add&lt;T, U&gt; m)
{
	return m.eval();
}

int main()
{
	double t1 = !(1.0,Thousand);	
	double m1 = !(1.0,Million);
	double b1 = (1,Billion).eval();
	assert(t1 == 1000.0);
	assert(m1 == 1000000.0);
	assert(b1 == 1000000000.0);

	double t2 = !(1.0,Thousand,100.0);	
	double m2 = !(1.0,Million,100.0);
	double b2 = !(1.0,Billion,100.0);
	assert(t2 == 1100.0);
	assert(m2 == 1000100.0);
	assert(b2 == 1000000100.0);

	double m3 = !(1.0,Million,1.0,Thousand);
	assert(m3 == 1001000.0);
	double m4 = !(1.0,Million,1.0,Thousand,1.0);
	assert(m4 == 1001001.0);

	double b3 = !(1.0,Billion,1.0,Thousand);
	assert(b3 == 1000001000.0);
	double b4 = !(1.0,Billion,1.0,Thousand,1.0);
	assert(b4 == 1000001001.0);
	double b5 = !(1.0,Billion,1.0,Million);
	assert(b5 == 1001000000.0);
	double b6 = !(1.0,Billion,1.0,Million,1.0);
	assert(b6 == 1001000001.0);

	double b7 = !(1.0,Billion,1.0,Million,1.0,Thousand);
	assert(b7 == 1001001000.0);

	double b8 = !(1.0,Billion,1.0,Million,1.0,Thousand,1.0);
	assert(b8 == 1001001001.0);

         // Wird korrekterweise als Fehlerhaft gemeldet:
        !(1.0,Billion, 1.0,Million, 1.0,Billion);
        !(1.0,Thousand,1.0,Million);
}
</code></pre>
<p>Er ist an einigen Stellen absichtlich etwas umständlicher, damit auch der VC 6.0 damit zurecht kommt (hier muss man allerdings einen anderen als den Komma-Operator verwenden. Z.B. operator|).</p>
<p>Warum belästige ich das Forum damit?<br />
Ganz einfach. Mir scheint ich habe mal wieder den schwachsinnigsten Weg gewählt und diesen möglichst kompliziert und inellegant implementiert.</p>
<p>Ich habe das sichere Gefühl, dass es eine viel einfachere und ellegantere Lösung gibt.<br />
Z.B. durch die geschickte Anwendung des Präprozessors.<br />
Würde mich also über Hinweise freuen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334016</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334016</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Sat, 16 Aug 2003 22:37:38 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sat, 16 Aug 2003 23:11:41 GMT]]></title><description><![CDATA[<p>mal ne bloede frage:</p>
<p>was spricht gegen</p>
<p>2*Million+3*Thousand+7*Hundred+9<br />
liest sich IMHO auch nicht schlechter als<br />
!(1.0,Billion,1.0,Million,1.0);</p>
<p>klar, ist nicht so geil templatetisiert, sondern einfach nur konstanten...</p>
<p>aber ich koennte mir ja auch ein<br />
Million(3)+Thousand(7)+Plain(6)<br />
vorstellen - aber irgendwie hapert die syntax immer...</p>
<p>es waere besser, wenn mann</p>
<p>2_000_000 schreiben koennte (@Ruby schaue)</p>
<p>ideal waere wohl ein<br />
Number(2,356,000);<br />
geht aber leider nicht - man muesste die fuehrenden 0 irgendwie wegbekommen...</p>
<p>uU mit<br />
Number(2,.356,.000); ?<br />
aber das waere auch doof</p>
<p>ne, also ich finde keine vernuenftige loesung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
mir fallen zwar loesungen ein - aber das problem ist die anwendung, denn diese sollte ja intuitiv sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334025</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sat, 16 Aug 2003 23:11:41 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sat, 16 Aug 2003 23:30:18 GMT]]></title><description><![CDATA[<p>Wie wäre es wenn du es anders machst.</p>
<p>2 Zahlen, sagen wir number, und number_null.<br />
number ist die 'Zahl' die in der Zahl ist. Also bei 1000 1 oder bei 12450 wärs 1245.<br />
und bei number_null gibst du einfach die zahl der Nullen an. also bei 1000 wär das dann 3...</p>
<p>Devil</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334030</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334030</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Sat, 16 Aug 2003 23:30:18 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 00:10:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#define Millionen * (1000000.0)
#define Thousand * (1000.0)
#define Hundred * (100.0)

float zahl = 2 Millionen + 3 Thousand + 5 Hundred;
</code></pre>
<p>this way ?</p>
<p>gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334041</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334041</guid><dc:creator><![CDATA[nameless]]></dc:creator><pubDate>Sun, 17 Aug 2003 00:10:51 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 00:59:06 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/3288">@nameless</a>:<br />
ah, das gefaellt mir sehr gut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334049</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 17 Aug 2003 00:59:06 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 10:28:41 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/3288">@nameless</a><br />
Exakt die selben defines habe ich auch ausprobiert.</p>
<p>Das einzige was mich daran stört ist, dass ich hier beliebig mischen kann:<br />
double d = 1 Hundred + 1 Thousand; -&gt; Das könnte man als Hunderttausend interpretieren, deshalb führt sowas in meinem Ansatz zu einem Compiler-Fehler.<br />
Genauso wie die Wiederholung:<br />
double d = 1 Hundred + 1 Hundred + 1 Million + 1 Hundred;</p>
<p>Das ist irgendwie unintuitiv. Die Templates zwingen mich immer zu einer absteigenden Anordnung ohne Wiederholung.</p>
<p>Naja, vergleicht man aber Aufwand und Nutzen, dann ist die define-Variante weit vorn <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/334139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334139</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Sun, 17 Aug 2003 10:28:41 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 12:31:27 GMT]]></title><description><![CDATA[<p>HumeSikkins schrieb:</p>
<blockquote>
<p>Money price = 2000000000.0;<br />
oder:<br />
Money salary = 2000000.0;<br />
Nun neige ich dazu mich bei den vielen Nullen zu vertippen, also wollte ich die magischen Zahlen durch symbolische Konstanten ersetzen. So in etwa:<br />
Money price = 2 Billion;</p>
</blockquote>
<p>ja, das würde mich auch stören. deswegen hab ich auswendig gelernt, daß ne milliarde 9 und ne million 6 hat.<br />
Money price = 2e9;<br />
oder:<br />
Money salary = 2e6;<br />
man kann damit sogar in maßen mischen!<br />
Money salery = 2.345e6;<br />
oder für freaks:<br />
Money Salery = 2e9 + 345e6;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334212</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334212</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 17 Aug 2003 12:31:27 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 12:34:02 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Number(2,356,000);<br />
geht aber leider nicht - man muesste die fuehrenden 0 irgendwie wegbekommen...</p>
</blockquote>
<p>Ich denke, es geht: Zwischen zwei Kommas stehen immer 3 Stellen. Man muss also mit dem ganzen va_arg-Scheiß die &quot;Ziffern&quot; im 1000-er-System auswerten. Oder ohne va_arg geht wohl auch. Mit entsprechend überladenen Operatoren:<br />
Number/2,000,000. Die Klasse muss natürlich auch operator int() etc. haben...<br />
Der Fantasie sind keine Grenzen gesetzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334213</guid><dc:creator><![CDATA[Mr. N]]></dc:creator><pubDate>Sun, 17 Aug 2003 12:34:02 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 13:18:29 GMT]]></title><description><![CDATA[<p>So. Jetzt hab ich das auch implementiert...</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

class Number_t { 
	int v; 
public:
	Number_t(int vv = 0) : v(vv) {}
	Number_t operator/(int o) {
		return o;
	}
	Number_t operator,(int o) {
		return v * 1000 + o;
	}
	friend ostream &amp;operator&lt;&lt;(ostream &amp;s, Number_t n) {
		s &lt;&lt; n.v;
	}
	operator int() { return v; }
} Number;

int main() {
	cout &lt;&lt; (Number/25,000,456) &lt;&lt; endl;
}
</code></pre>
<p>Und wer jetzt Bedenken wegen der Performance hat... der Compiler ist wunderbar in der Lage, das zu wegzuoptimieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334230</guid><dc:creator><![CDATA[Mr. N]]></dc:creator><pubDate>Sun, 17 Aug 2003 13:18:29 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 14:23:41 GMT]]></title><description><![CDATA[<p>HumeSikkins schrieb:</p>
<blockquote>
<p>Das einzige was mich daran stört ist, dass ich hier beliebig mischen kann:<br />
double d = 1 Hundred + 1 Thousand; -&gt; Das könnte man als Hunderttausend interpretieren</p>
</blockquote>
<p>sorry aber die argumentation versteh ich nicht...<br />
wenn ich &quot;1 Hundred + 1 Thousand&quot; stehen seh dann is das für mich ne rechnung deren ergebniss 1100 ist und das als hundertausend zu interpretieren ist doch sehr weit hiergeholt, oder?<br />
die makros erlauben es ja sogar &quot;1 Hundred Thousand&quot; zu schreiben und es kommt 100'000 raus wie man er erwarten würde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334264</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334264</guid><dc:creator><![CDATA[japro]]></dc:creator><pubDate>Sun, 17 Aug 2003 14:23:41 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 21:18:13 GMT]]></title><description><![CDATA[<blockquote>
<p>sorry aber die argumentation versteh ich nicht...</p>
</blockquote>
<p>Keiner verlangt von dir meinen beschränkten Verstand zu verstehen.<br />
Und das er beschränkt ist, hat mir Volkard mal wieder eindrücklich gezeigt. Seine Lösung ist genau die Offensichtliche, deren Existenz ich vermutete, die ich aber nicht finden konnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334548</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334548</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Sun, 17 Aug 2003 21:18:13 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Sun, 17 Aug 2003 22:44:46 GMT]]></title><description><![CDATA[<p>Hat jemand außer volkard schon meinen Denkfehler entdeckt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334595</guid><dc:creator><![CDATA[Mr. N]]></dc:creator><pubDate>Sun, 17 Aug 2003 22:44:46 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Mon, 18 Aug 2003 00:00:53 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int i = 2;
cout &lt;&lt; ((Number/25,000,000) / i) &lt;&lt; endl;
</code></pre>
<p>Liefert irgendwie nicht das Erwartete.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334643</guid><dc:creator><![CDATA[Christoph]]></dc:creator><pubDate>Mon, 18 Aug 2003 00:00:53 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Mon, 18 Aug 2003 10:27:05 GMT]]></title><description><![CDATA[<blockquote>
<p>Hat jemand außer volkard schon meinen Denkfehler entdeckt?</p>
</blockquote>
<p>Du dachtest, du hättest funktionsfähigen C++ Code gepostet?<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/334874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334874</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Mon, 18 Aug 2003 10:27:05 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Mon, 18 Aug 2003 12:02:23 GMT]]></title><description><![CDATA[<p>nee, viel lustiger.</p>
<pre><code class="language-cpp">cout &lt;&lt; (Number/2,468,024) &lt;&lt; endl;
</code></pre>
<p>das ding gibt nicht 2468024 aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/334972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/334972</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 18 Aug 2003 12:02:23 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Mon, 18 Aug 2003 13:55:47 GMT]]></title><description><![CDATA[<p>HumeSikkins schrieb:</p>
<blockquote>
<p>Du dachtest, du hättest funktionsfähigen C++ Code gepostet?<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Du dachtest ich hätte gedacht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/335107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335107</guid><dc:creator><![CDATA[Mr. N]]></dc:creator><pubDate>Mon, 18 Aug 2003 13:55:47 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Mon, 18 Aug 2003 20:22:23 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<pre><code class="language-cpp">cout &lt;&lt; (Number/2,468,024) &lt;&lt; endl;
</code></pre>
<p>das ding gibt nicht 2468024 aus.</p>
</blockquote>
<p>*plonk*<br />
Logisch. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/335450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335450</guid><dc:creator><![CDATA[Christoph]]></dc:creator><pubDate>Mon, 18 Aug 2003 20:22:23 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 10:36:55 GMT]]></title><description><![CDATA[<blockquote>
<p>Und das er beschränkt ist, hat mir Volkard mal wieder eindrücklich gezeigt. Seine Lösung ist genau die Offensichtliche, deren Existenz ich vermutete, die ich aber nicht finden konnte.</p>
</blockquote>
<p>Oh. Ich dachte am anfang du würdest das ausschreiben, weil dir diese schreibweise nicht gefällt.</p>
<p>Falls Geschwindigkeit nicht ganz so wichtig ist, könnte man ja auch einen string paresen. Dann hat man sowas Money(&quot;2.332.1213,12&quot;) oder so.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/335765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335765</guid><dc:creator><![CDATA[Helium]]></dc:creator><pubDate>Tue, 19 Aug 2003 10:36:55 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 10:40:31 GMT]]></title><description><![CDATA[<p>Was haltet ihr davon:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cassert&gt;
using namespace std;

class Number
{
public:
	Number(unsigned int n) : _n(n) {}
	Number operator()(Number i) const
	{
		assert(i._n &lt;= _n);
		return _n + i._n;
	}
	unsigned int operator()(unsigned int i = 0) const
	{
		assert(i &lt; 1000);
		return _n + i;
	}
private:
	const unsigned int _n;
};

template &lt;int n&gt; class Number_temp {};

template &lt;int n&gt;
Number operator*(int i, Number_temp&lt;n&gt;)
{
	assert(i &lt; 1000);
	return n * i;
}

#define Billion   * Number_temp&lt;1000000000&gt;())(
#define Million   * Number_temp&lt;1000000&gt;())(
#define Thousand  * Number_temp&lt;1000&gt;())(

int main()
{
         // Funktioniert
	unsigned int MyNumber1 = Number(1 Billion 20 Million 24 Thousand 123);
	unsigned int MyNumber2 = Number(123 Million);
         // Wird als falsch erkannt:
	unsigned int MyNumber3 = Number(50 Million 1 Billion);
         // Auch falsch
	unsigned int MyNumber4 = Number(1 Billion 20 Million 24 Thousand 1892);
         // Auch falsch
	unsigned int MyNumber5 = Number(1 Billion 1 Billion 24 Thousand 123);
         // Auch falsch
	unsigned int MyNumber5 = Number(1 Billion 5950 Thousand 123);

	cout &lt;&lt; MyNumber1 &lt;&lt; endl;
	return 0;
}
</code></pre>
<p>Die Zahleneingabe ist intuitiv wie bei der reinen Makro-Variante, plus eine Fehlererkennung. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Falsche Zahlen werden allerdings erst zur Laufzeit durch die Asserts erkannt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/335767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335767</guid><dc:creator><![CDATA[Christoph]]></dc:creator><pubDate>Tue, 19 Aug 2003 10:40:31 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 10:54:42 GMT]]></title><description><![CDATA[<p>Vielleicht geht's ja wirklich nur mir so, aber ich finde &quot;123456789.12&quot; ja noch übersichtlicher als &quot;123 Milion 456 Thousand 769.12&quot;. Und da eine englische eingaber scheibar gefordert ist kann man meinen vorgeschlagenen Parser ja anpassen Money(&quot;123,456,789.12&quot;).</p>
<p>Vor allem solche angaben sind doch bei euch immer noch möglich: 1 Million 5000 Thousand. Soll heißen 6 Millionen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/335779</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335779</guid><dc:creator><![CDATA[Helium]]></dc:creator><pubDate>Tue, 19 Aug 2003 10:54:42 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 10:52:17 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/1836">@Helium</a><br />
Die String-Variante ist in meiner Money-Klasse bereits drin. Natürlich mit wählbarem Grouping und Thousand-Seperator <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/335782</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335782</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Tue, 19 Aug 2003 10:52:17 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 12:02:17 GMT]]></title><description><![CDATA[<p>Frei nach Asterix: Die spinnen, die cpp-ler *g*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/335874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335874</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Tue, 19 Aug 2003 12:02:17 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 12:34:37 GMT]]></title><description><![CDATA[<p>cd9000 schrieb:</p>
<blockquote>
<p>Was haltet ihr davon:<br />
unsigned int MyNumber5 = Number(1 Billion 1 Billion 24 Thousand 123);</p>
</blockquote>
<p>auch das ist meines erachtens nach zu gefährlich wegen<br />
unsigned int gibi1 = 1073741824;<br />
unsigned int gibi2 = Number(1 Billion 073 Million 741 Thousand 824);<br />
und der rätselhaften ausgabe von cout&lt;&lt;gibi2; mit 1059741824<br />
und wer läßt schon gerne auf solcherlei weise 14 millionen verschwinden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/335911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/335911</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 19 Aug 2003 12:34:37 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 17:24:45 GMT]]></title><description><![CDATA[<p>Wer würde bei dieser Syntax schon Oktalzahlen schreiben?</p>
<p>Dann kann man es auch gleich so machen:</p>
<pre><code class="language-cpp">class Number
{
  public: Number(const std::string&amp;);
};
#define Number(n) Number(&quot;n&quot;)
</code></pre>
<p>Und im Parser Oktalzahlen korrigieren. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/336182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/336182</guid><dc:creator><![CDATA[Christoph]]></dc:creator><pubDate>Tue, 19 Aug 2003 17:24:45 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 18:03:05 GMT]]></title><description><![CDATA[<p>cd9000 schrieb:</p>
<blockquote>
<p>Dann kann man es auch gleich so machen:<br />
#define Number(n) Number(&quot;n&quot;)</p>
</blockquote>
<p>das glaube ich nicht, tim.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/336217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/336217</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 19 Aug 2003 18:03:05 GMT</pubDate></item><item><title><![CDATA[Reply to Schwachsinniger Code für Zwischendurch on Tue, 19 Aug 2003 18:48:50 GMT]]></title><description><![CDATA[<p>Das war natürlich Pseudo-Code. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/336259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/336259</guid><dc:creator><![CDATA[Christoph]]></dc:creator><pubDate>Tue, 19 Aug 2003 18:48:50 GMT</pubDate></item></channel></rss>