invoking rope/stl member function


On my linux SUSE11.0 workstation I am able to compile, link, and run the following c++ code invoking rope:

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


with stlport (same outcome with other versions/implementations of rope).

It functions correctly; however, I need to use the rope member:

void replace(const iterator& f1, const iterator& l1,const iterator& f2, const iterator& l2)
which effectively replaces the substring [f1,l1] by the substring [f2,l2] .

I tried e.g.

1
2
3
int if1;
const iterator &f1 = if1;
v.replace(f1,...)


or casting, v.replace((iterator&) if1, ... )

and all kinds of permutations and variations thereof, but I always get an
error (often, the compiler asks to make a choice between two overloadings of
replace, neither of which is appropriate).

[Rope is necessary because I am inserting and deleting from huge strings; I have checked
that for the members that I can get to work, they are much faster than string class.] I am a novice at C++ .



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <rope>
#include <string>
#include <iostream>

using namespace std;

template <class T>
class test
{
  public:
  test( int b , int i );
};

template <class T>
test<T>::test( int b , int n )
{

// tests OK ========================================
// crope r1(1000000,'x');
// crope r2=r1+"A";
// reverse(r2.mutable_begin(),r2.mutable_end());
// tests OK ========================================

 T s( b , 'a' );
 T v;
 v=s;

 for ( int i = 0 ; i < n ; ++i ) {
  v = s;
  v.insert( 0 , "qwerty" );
  cout << v << endl;
  int j;
  for(j=0;j<10;j++) v.append( "i" );
  for(j=0;j<2;j++) v.insert( 10 / 2 , "zxcvb" );
  v.replace( b / 2 , 20U, "abcdefg" );
// ?????????????????????????????????????????????????????????
// v.replace(1,2,3,4);
// ?????????????????????????????????????????????????????????
  cout << v << endl;
 }
}

int bs;
int n;
// bool use_str = true;
bool use_str = false;

int main ( int argc , char * const *argv )
{
bs=10; n=1;
 if ( !use_str ) {
  test<rope<char> > t( bs , n );
 } else {
  test<string> t( bs , n );
 }
 return 0 ;
}


// linking and compilation:
// #!/bin/bash
// LD_LIBRARY_PATH=/usr/local/STLport-5.2.1/build/lib/obj/gcc/so
// export LD_LIBRARY_PATH
// c++ -pthread -fexceptions -O2 -I/usr/local/STLport-5.2.1/stlport -c -o mytest.o mytest.cpp
// c++ -pthread -fexceptions -O2 -I/usr/local/STLport-5.2.1/stlport -o mytest mytest.o -lstlport
// ./mytest

Last edited on
Welcome to the forums, can you please use code tags for formatting when using sample code
----> the buttons on the right "<>"
Topic archived. No new replies allowed.