<?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[vorstellung: strings mit expression templates]]></title><description><![CDATA[<p>hab gerade wiedermal <a href="http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html" rel="nofollow">http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html</a> ausgegraben und mich an strings versucht.</p>
<p>bisher ist das dabei rausgekommen:<br />
(ist teil meiner vlib, daher heißt ostream Writer und size_t Size)</p>
<pre><code class="language-cpp">#include &quot;iostream.hpp&quot;

template&lt;typename A,typename B&gt;
struct OpPlus {
	typedef OpPlus StringPart;
	A const&amp; a;
	B const&amp; b;
	OpPlus(A const&amp; _a,B const&amp; _b):
	a(_a),
	b(_b)
	{
	}
	Size getSize() const{
		return a.getSize()+b.getSize();
	}
	char* writeAt(char* dst) const{
		char* tmp=a.writeAt(dst);
		return b.writeAt(tmp);
	}
};

class SubString{
private:
	char const* begin;
	char const* end;
public:
	typedef SubString StringPart;
	SubString(char* _begin,char* _end) :
			begin(_begin),
	end(_end) {}
	Size getSize() const {
		return end-begin;
	}
	char* writeAt(char* b) const {
		__builtin_memcpy(b,begin,end-begin);
		return b+(end-begin);
	}
};

template&lt;Size size&gt;
class StringLiteral {
private:
	char const* begin;
public:
	typedef StringLiteral StringPart;
	StringLiteral(char const* _begin):
	begin(_begin) {}
	Size getSize() const{
		return size;
	}
	char* writeAt(char* dst) const{
		__builtin_memcpy(dst,begin,size);
		return dst+size;
	}
	void printAt(Writer&amp; out) const{
		out.write(begin,begin+size);
	}
};

#define SL(x) (StringLiteral&lt;sizeof(x)-1&gt;(x))

class String {
private:
	char* begin;
	char* end;
public:
	typedef String StringPart;
	template&lt;Size size&gt;
	String(StringLiteral&lt;size&gt; const&amp; sl){
		cout&lt;&lt;&quot;::new\n&quot;;
		begin=new char[size];
		end=sl.writeAt(begin);
	}
	template&lt;typename A,typename B&gt;
	String(OpPlus&lt;A,B&gt; const&amp; op) {
		Size size=op.getSize();
		cout&lt;&lt;&quot;::new\n&quot;;
		begin=new char[size];
		end=op.writeAt(begin);
	}
	char* writeAt(char* b) const {
		__builtin_memcpy(b,begin,end-begin);
		return b+(end-begin);
	}
	Size getSize() const{
		return end-begin;
	}
	void printAt(Writer&amp; out) const{
		out.write(begin,end);
	}
	SubString substr(Size _begin,Size _end){
		return SubString(begin+_begin,begin+_end);
	}
};

//edit: hier ist wohl ein kommentar nötig:
//SFINAE
template&lt;typename A,typename B&gt;
OpPlus&lt;typename A::StringPart,typename B::StringPart&gt; operator+(A const&amp; a,B const&amp; b){
	return OpPlus&lt;A,B&gt;(a,b);
}

int main() {
	String a=SL(&quot;hallo&quot;);
	cout&lt;&lt;a&lt;&lt;endl;
	StringLiteral&lt;1&gt; b=&quot;+&quot;;
	cout&lt;&lt;b&lt;&lt;endl;
	String c=SL(&quot;welt&quot;);
	cout&lt;&lt;c&lt;&lt;endl;
	String x=a+b+c+a.substr(2,4)+b+c;
	cout&lt;&lt;x&lt;&lt;endl;
}
</code></pre>
<p>ausgabe:</p>
<pre><code>::new
hallo
+
::new
welt
::new
hallo+weltll+welt
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/143803/vorstellung-strings-mit-expression-templates</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 11:30:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/143803.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Apr 2006 21:50:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to vorstellung: strings mit expression templates on Tue, 11 Apr 2006 21:52:35 GMT]]></title><description><![CDATA[<p>hab gerade wiedermal <a href="http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html" rel="nofollow">http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html</a> ausgegraben und mich an strings versucht.</p>
<p>bisher ist das dabei rausgekommen:<br />
(ist teil meiner vlib, daher heißt ostream Writer und size_t Size)</p>
<pre><code class="language-cpp">#include &quot;iostream.hpp&quot;

template&lt;typename A,typename B&gt;
struct OpPlus {
	typedef OpPlus StringPart;
	A const&amp; a;
	B const&amp; b;
	OpPlus(A const&amp; _a,B const&amp; _b):
	a(_a),
	b(_b)
	{
	}
	Size getSize() const{
		return a.getSize()+b.getSize();
	}
	char* writeAt(char* dst) const{
		char* tmp=a.writeAt(dst);
		return b.writeAt(tmp);
	}
};

class SubString{
private:
	char const* begin;
	char const* end;
public:
	typedef SubString StringPart;
	SubString(char* _begin,char* _end) :
			begin(_begin),
	end(_end) {}
	Size getSize() const {
		return end-begin;
	}
	char* writeAt(char* b) const {
		__builtin_memcpy(b,begin,end-begin);
		return b+(end-begin);
	}
};

template&lt;Size size&gt;
class StringLiteral {
private:
	char const* begin;
public:
	typedef StringLiteral StringPart;
	StringLiteral(char const* _begin):
	begin(_begin) {}
	Size getSize() const{
		return size;
	}
	char* writeAt(char* dst) const{
		__builtin_memcpy(dst,begin,size);
		return dst+size;
	}
	void printAt(Writer&amp; out) const{
		out.write(begin,begin+size);
	}
};

#define SL(x) (StringLiteral&lt;sizeof(x)-1&gt;(x))

class String {
private:
	char* begin;
	char* end;
public:
	typedef String StringPart;
	template&lt;Size size&gt;
	String(StringLiteral&lt;size&gt; const&amp; sl){
		cout&lt;&lt;&quot;::new\n&quot;;
		begin=new char[size];
		end=sl.writeAt(begin);
	}
	template&lt;typename A,typename B&gt;
	String(OpPlus&lt;A,B&gt; const&amp; op) {
		Size size=op.getSize();
		cout&lt;&lt;&quot;::new\n&quot;;
		begin=new char[size];
		end=op.writeAt(begin);
	}
	char* writeAt(char* b) const {
		__builtin_memcpy(b,begin,end-begin);
		return b+(end-begin);
	}
	Size getSize() const{
		return end-begin;
	}
	void printAt(Writer&amp; out) const{
		out.write(begin,end);
	}
	SubString substr(Size _begin,Size _end){
		return SubString(begin+_begin,begin+_end);
	}
};

//edit: hier ist wohl ein kommentar nötig:
//SFINAE
template&lt;typename A,typename B&gt;
OpPlus&lt;typename A::StringPart,typename B::StringPart&gt; operator+(A const&amp; a,B const&amp; b){
	return OpPlus&lt;A,B&gt;(a,b);
}

int main() {
	String a=SL(&quot;hallo&quot;);
	cout&lt;&lt;a&lt;&lt;endl;
	StringLiteral&lt;1&gt; b=&quot;+&quot;;
	cout&lt;&lt;b&lt;&lt;endl;
	String c=SL(&quot;welt&quot;);
	cout&lt;&lt;c&lt;&lt;endl;
	String x=a+b+c+a.substr(2,4)+b+c;
	cout&lt;&lt;x&lt;&lt;endl;
}
</code></pre>
<p>ausgabe:</p>
<pre><code>::new
hallo
+
::new
welt
::new
hallo+weltll+welt
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1035557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035557</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 11 Apr 2006 21:52:35 GMT</pubDate></item><item><title><![CDATA[Reply to vorstellung: strings mit expression templates on Wed, 12 Apr 2006 08:24:54 GMT]]></title><description><![CDATA[<p>Hi Volkard,<br />
zumindest zum Thema String Konkatenation mittels Expression Templates gab es im CUJ schonmal einen Artikel (Juni 2005 - &quot;String Concatenation &amp; Expression Templates&quot;). Den Code gibt es hier:</p>
<p><a href="ftp://ftp.cuj.com/pub/2005/cujjun2005.zip" rel="nofollow">ftp://ftp.cuj.com/pub/2005/cujjun2005.zip</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035703</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Wed, 12 Apr 2006 08:24:54 GMT</pubDate></item><item><title><![CDATA[Reply to vorstellung: strings mit expression templates on Wed, 12 Apr 2006 09:45:37 GMT]]></title><description><![CDATA[<p>HumeSikkins schrieb:</p>
<blockquote>
<p>Hi Volkard,<br />
zumindest zum Thema String Konkatenation mittels Expression Templates gab es im CUJ schonmal einen Artikel (Juni 2005 - &quot;String Concatenation &amp; Expression Templates&quot;). Den Code gibt es hier:<br />
<a href="ftp://ftp.cuj.com/pub/2005/cujjun2005.zip" rel="nofollow">ftp://ftp.cuj.com/pub/2005/cujjun2005.zip</a></p>
</blockquote>
<p>danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035770</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035770</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 12 Apr 2006 09:45:37 GMT</pubDate></item></channel></rss>