Note that there are some explanatory texts on larger screens.

plurals
  1. POtemplated typedef?
    text
    copied!<p>I'm using libgc, a garbage collector for C and C++. To make STL containers garbage collectible one must use the gc_allocator. </p> <p>Instead of writing </p> <pre><code>std::vector&lt;MyType&gt; </code></pre> <p>one has to write </p> <pre><code>std::vector&lt;MyType,gc_allocator&lt;MyType&gt; &gt; </code></pre> <p>Could there be a way to define something like <p></p> <pre><code>template&lt;class T&gt; typedef std::vector&lt;T,gc_allocator&lt;T&gt; &gt; gc_vector&lt;T&gt;; </code></pre> <p>I checked some time ago and found out it was not possible. But I may have been wrong or there might be another way around. </p> <p>Defining maps in this way is particularly unpleasing.</p> <pre><code>std::map&lt;Key,Val&gt; </code></pre> <p>becomes</p> <pre><code>std::map&lt;Key,Val, std::less&lt;Key&gt;, gc_allocator&lt; std::pair&lt;const Key, Val&gt; &gt; &gt; </code></pre> <p>EDIT: After trying the use of macro I found out the following code breaks it:</p> <pre><code>#define gc_vector(T) std::vector&lt;T, gc_allocator&lt;T&gt; &gt; typedef gc_vector( std::pair&lt; int, float &gt; ) MyVector; </code></pre> <p>The comma inside the templated type definition is interpreted as a macro argument separator. </p> <p>So it seems the inner class/struct is the best solution.</p> <p>Here is an example on how it will be done in C++0X</p> <pre><code>// standard vector using my allocator template&lt;class T&gt; using gc_vector = std::vector&lt;T, gc_allocator&lt;T&gt; &gt;; // allocates elements using My_alloc gc_vector &lt;double&gt; fib = { 1, 2, 3, 5, 8, 13 }; // verbose and fib are of the same type vector&lt;int, gc_vector &lt;int&gt;&gt; verbose = fib; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload