public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gokhan Kisacikoglu <kisa@centropolisfx.com>
To: Thomas Maier <T.Maier@epost.de>
Cc: gcc-help@gcc.gnu.org, Thomas Maier <T.Maier@tu-bs.de>
Subject: Re: template problems
Date: Fri, 26 Jul 2002 11:08:00 -0000	[thread overview]
Message-ID: <3D4190CA.D8F0C61A@centropolisfx.com> (raw)
In-Reply-To: <1027675013.2062.70.camel@marvin>

I am not sure you can pass address of template functions, especially
when these functions are relative to a certain instance (not static), I
don't know how it would all work. Is this described in the ISO spec? I
am not sure... Maybe somebody can tell us more...

> wanted to write an assoc_insert_iterator to insert a value into a map
> like a back_inserter (gives a back_insert_iterator that) inserts into a
> list, for example.  The iterator needs to be parameterized with some X

You can already do this, if you have your value_types (pair of key and
data) stored in an array let's say, that you want to insert them into a
map by using the insert_iterator, you could easily type the following;

#include <map>
#include <vector>
#include <iterator>
#include <string>
#include <iostream>

using namespace std; 	// for simplicity

// a simple mapping
//
typedef pair <int, string> int_string_pair;

typedef map <int_string_pair :: first_type, 
	    int_string_pair :: second_type> mapped_strings;

// a simple array (let's say)
//	
typedef vector <int_string_pair> map_value_array;

int main(void)
{
    // instances
    //
    
    // value in an arrays
    //	
    map_value_array array;
    
    array.reserve(3);
    array.push_back( make_pair( 1, "one" ) );
    array.push_back( make_pair( 3, "three" ) );	// randomly ordered
    array.push_back( make_pair( 2, "two" ) );
    
    // insert into a map instance
    //	
    mapped_strings mstrs;
    
    copy( array.begin(), array.end(), 
	insert_iterator <mapped_strings> (mstrs, mstrs.end()) );
    
    mapped_strings :: iterator iter = mstrs.begin();
    cerr << iter->first << " " << iter->second << endl; ++ iter;
    cerr << iter->first << " " << iter->second << endl; ++ iter;
    cerr << iter->first << " " << iter->second << endl; ++ iter;
    
    assert( iter == mstrs.end() );
    
    return 0;
}

check out:

http://www.sgi.com/tech/stl/insert_iterator.html

The second parameter is the hint to tell where to start the search for
the appropriate insertion location in the case of map, it would be the
exact insertion point in the case of list for example...

HTH,
Gokhan

  reply	other threads:[~2002-07-26 18:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-26  2:07 Thomas Maier
2002-07-26 11:08 ` Gokhan Kisacikoglu [this message]
2002-07-26 15:18   ` Thomas Maier
2002-07-26 16:34     ` Gokhan Kisacikoglu
  -- strict thread matches above, loose matches on Subject: below --
2002-07-26  2:02 Thomas Maier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D4190CA.D8F0C61A@centropolisfx.com \
    --to=kisa@centropolisfx.com \
    --cc=T.Maier@epost.de \
    --cc=T.Maier@tu-bs.de \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).