OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc4/] [libstdc++-v3/] [doc/] [xml/] [manual/] [backwards_compatibility.xml] - Blame information for rev 519

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
2
3
 
4
5
  
6
    
7
      ISO C++
8
    
9
    
10
      backwards
11
    
12
  
13
14
 
15
Backwards Compatibility
16
 
17
18
First
19
 
20
The first generation GNU C++ library was called libg++.  It was a
21
separate GNU project, although reliably paired with GCC. Rumors imply
22
that it had a working relationship with at least two kinds of
23
dinosaur.
24
25
 
26
Some background: libg++ was designed and created when there was no
27
ISO standard to provide guidance.  Classes like linked lists are now
28
provided for by list<T> and do not need to be
29
created by genclass.  (For that matter, templates exist
30
now and are well-supported, whereas genclass (mostly) predates them.)
31
32
 
33
There are other classes in libg++ that are not specified in the
34
ISO Standard (e.g., statistical analysis).  While there are a lot of
35
really useful things that are used by a lot of people, the Standards
36
Committee couldn't include everything, and so a lot of those
37
obvious classes didn't get included.
38
39
 
40
Known Issues include many of the limitations of its immediate ancestor.
41
 
42
Portability notes and known implementation limitations are as follows.
43
 
44
45
  No <code>ios_base</code>
46
 
47
 At least some older implementations don't have std::ios_base, so you should use std::ios::badbit, std::ios::failbit and std::ios::eofbit and std::ios::goodbit.
48
49
50
 
51
52
No <code>cout</code> in <code>ostream.h</code>, no <code>cin</code> in <code>istream.h</code>
53
 
54
55
        In earlier versions of the standard,
56
        fstream.h,
57
        ostream.h
58
        and istream.h
59
        used to define
60
        cout, cin and so on. ISO C++ specifies that one needs to include
61
        iostream
62
        explicitly to get the required definitions.
63
 
64
 Some include adjustment may be required.
65
 
66
This project is no longer maintained or supported, and the sources
67
archived. For the desperate,
68
the GCC extensions
69
page describes where to find the last libg++ source. The code is
70
considered replaced and rewritten.
71
72
73
74
 
75
76
Second
77
 
78
79
  The second generation GNU C++ library was called libstdc++, or
80
  libstdc++-v2. It spans the time between libg++ and pre-ISO C++
81
  standardization and is usually associated with the following GCC
82
  releases: egcs 1.x, gcc 2.95, and gcc 2.96.
83
84
 
85
86
  The STL portions of this library are based on SGI/HP STL release 3.11.
87
88
 
89
90
  This project is no longer maintained or supported, and the sources
91
  archived.  The code is considered replaced and rewritten.
92
93
 
94
95
  Portability notes and known implementation limitations are as follows.
96
97
 
98
99
  Namespace <code>std::</code> not supported
100
 
101
  
102
    Some care is required to support C++ compiler and or library
103
    implementation that do not have the standard library in
104
    namespace std.
105
  
106
 
107
  
108
    The following sections list some possible solutions to support compilers
109
    that cannot ignore std::-qualified names.
110
  
111
 
112
  
113
    First, see if the compiler has a flag for this. Namespace
114
    back-portability-issues are generally not a problem for g++
115
    compilers that do not have libstdc++ in std::, as the
116
    compilers use -fno-honor-std (ignore
117
    std::, :: = std::) by default. That is,
118
    the responsibility for enabling or disabling std:: is
119
    on the user; the maintainer does not have to care about it. This
120
    probably applies to some other compilers as well.
121
  
122
 
123
  
124
    Second, experiment with a variety of pre-processor tricks.
125
  
126
 
127
  
128
    By defining std as a macro, fully-qualified namespace
129
    calls become global. Volia.
130
  
131
 
132
133
#ifdef WICKEDLY_OLD_COMPILER
134
# define std
135
#endif
136
137
 
138
  
139
    Thanks to Juergen Heinzl who posted this solution on gnu.gcc.help.
140
  
141
 
142
  
143
    Another pre-processor based approach is to define a macro
144
    NAMESPACE_STD, which is defined to either
145
      or std based on a compile-type
146
    test. On GNU systems, this can be done with autotools by means of
147
    an autoconf test (see below) for HAVE_NAMESPACE_STD,
148
    then using that to set a value for the NAMESPACE_STD
149
    macro.  At that point, one is able to use
150
    NAMESPACE_STD::string, which will evaluate to
151
    std::string or ::string (i.e., in the
152
    global namespace on systems that do not put string in
153
    std::).
154
  
155
 
156
157
dnl @synopsis AC_CXX_NAMESPACE_STD
158
dnl
159
dnl If the compiler supports namespace std, define
160
dnl HAVE_NAMESPACE_STD.
161
dnl
162
dnl @category Cxx
163
dnl @author Todd Veldhuizen
164
dnl @author Luc Maisonobe <luc@spaceroots.org>
165
dnl @version 2004-02-04
166
dnl @license AllPermissive
167
AC_DEFUN([AC_CXX_NAMESPACE_STD], [
168
  AC_CACHE_CHECK(if g++ supports namespace std,
169
  ac_cv_cxx_have_std_namespace,
170
  [AC_LANG_SAVE
171
  AC_LANG_CPLUSPLUS
172
  AC_TRY_COMPILE([#include <iostream>
173
                  std::istream& is = std::cin;],,
174
  ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
175
  AC_LANG_RESTORE
176
  ])
177
  if test "$ac_cv_cxx_have_std_namespace" = yes; then
178
    AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
179
  fi
180
])
181
182
183
 
184
185
Illegal iterator usage
186
187
  The following illustrate implementation-allowed illegal iterator
188
  use, and then correct use.
189
190
 
191
192
  
193
    
194
      you cannot do ostream::operator<<(iterator)
195
      to print the address of the iterator => use
196
      operator<< &*iterator instead
197
    
198
  
199
  
200
    
201
      you cannot clear an iterator's reference (iterator =
202
      0) => use iterator = iterator_type();
203
    
204
  
205
  
206
    
207
      if (iterator) won't work any more => use
208
      if (iterator != iterator_type())
209
    
210
  
211
212
213
 
214
215
  <code>isspace</code> from <filename class="headerfile">cctype</filename> is a macro</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>216</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  
217
 
218
  
219
    Glibc 2.0.x and 2.1.x define 
220
    class="headerfile">ctype.h functionality as macros
221
    (isspace, isalpha etc.).
222
  
223
 
224
  
225
    This implementations of libstdc++, however, keep these functions
226
    as macros, and so it is not back-portable to use fully qualified
227
    names. For example:
228
  
229
 
230
231
#include <cctype>
232
int main() { std::isspace('X'); }
233
234
 
235
236
  Results in something like this:
237
238
 
239
240
std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ;
241
242
 
243
244
  A solution is to modify a header-file so that the compiler tells
245
  ctype.h to define functions
246
  instead of macros:
247
248
 
249
250
// This keeps isalnum, et al from being propagated as macros.
251
#if __linux__
252
# define __NO_CTYPE 1
253
#endif
254
255
 
256
257
  Then, include ctype.h
258
259
 
260
261
  Another problem arises if you put a using namespace
262
  std; declaration at the top, and include 
263
  class="headerfile">ctype.h. This will result in
264
  ambiguities between the definitions in the global namespace
265
  (ctype.h) and the
266
  definitions in namespace std::
267
  (<cctype>).
268
269
270
 
271
272
No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code>
273
 
274
275
  One solution is to add an autoconf-test for this:
276
277
 
278
279
AC_MSG_CHECKING(for container::at)
280
AC_TRY_COMPILE(
281
[
282
#include <vector>
283
#include <deque>
284
#include <string>
285
 
286
using namespace std;
287
],
288
[
289
deque<int> test_deque(3);
290
test_deque.at(2);
291
vector<int> test_vector(2);
292
test_vector.at(1);
293
string test_string(test_string);
294
test_string.at(3);
295
],
296
[AC_MSG_RESULT(yes)
297
AC_DEFINE(HAVE_CONTAINER_AT)],
298
[AC_MSG_RESULT(no)])
299
300
 
301
302
  If you are using other (non-GNU) compilers it might be a good idea
303
  to check for string::at separately.
304
305
 
306
307
 
308
309
No <code>std::char_traits<char>::eof</code>
310
 
311
312
  Use some kind of autoconf test, plus this:
313
314
 
315
316
#ifdef HAVE_CHAR_TRAITS
317
#define CPP_EOF std::char_traits<char>::eof()
318
#else
319
#define CPP_EOF EOF
320
#endif
321
322
 
323
324
 
325
326
No <code>string::clear</code>
327
 
328
329
  There are two functions for deleting the contents of a string:
330
  clear and erase (the latter returns the
331
  string).
332
333
 
334
335
void
336
clear() { _M_mutate(0, this->size(), 0); }
337
338
 
339
340
basic_string&
341
erase(size_type __pos = 0, size_type __n = npos)
342
{
343
  return this->replace(_M_check(__pos), _M_fold(__pos, __n),
344
                          _M_data(), _M_data());
345
}
346
347
 
348
349
  Unfortunately, clear is not implemented in this
350
  version, so you should use erase (which is probably
351
  faster than operator=(charT*)).
352
353
354
 
355
356
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>357</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  Removal of <code>ostream::form</code> and <code>istream::scan</code></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>358</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  extensions</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>359</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
360
 
361
362
  These are no longer supported. Please use stringstreams instead.
363
364
365
 
366
367
No <code>basic_stringbuf</code>, <code>basic_stringstream</code>
368
 
369
370
  Although the ISO standard i/ostringstream-classes are
371
  provided, (sstream), for
372
  compatibility with older implementations the pre-ISO
373
  i/ostrstream (
374
  class="headerfile">strstream) interface is also provided,
375
  with these caveats:
376
377
 
378
379
  
380
    
381
      strstream is considered to be deprecated
382
    
383
  
384
  
385
    
386
      strstream is limited to char
387
    
388
  
389
  
390
    
391
      with ostringstream you don't have to take care of
392
      terminating the string or freeing its memory
393
    
394
  
395
  
396
    
397
      istringstream can be re-filled (clear();
398
      str(input);)
399
    
400
  
401
402
 
403
404
  You can then use output-stringstreams like this:
405
406
 
407
408
#ifdef HAVE_SSTREAM
409
# include <sstream>
410
#else
411
# include <strstream>
412
#endif
413
 
414
#ifdef HAVE_SSTREAM
415
  std::ostringstream oss;
416
#else
417
  std::ostrstream oss;
418
#endif
419
 
420
oss << Name= << m_name << , number= << m_number << std::endl;
421
...
422
#ifndef HAVE_SSTREAM
423
  oss << std::ends; // terminate the char*-string
424
#endif
425
 
426
// str() returns char* for ostrstream and a string for ostringstream
427
// this also causes ostrstream to think that the buffer's memory
428
// is yours
429
m_label.set_text(oss.str());
430
#ifndef HAVE_SSTREAM
431
  // let the ostrstream take care of freeing the memory
432
  oss.freeze(false);
433
#endif
434
435
 
436
437
      Input-stringstreams can be used similarly:
438
439
 
440
441
std::string input;
442
...
443
#ifdef HAVE_SSTREAM
444
std::istringstream iss(input);
445
#else
446
std::istrstream iss(input.c_str());
447
#endif
448
 
449
int i;
450
iss >> i;
451
452
 
453
 One (the only?) restriction is that an istrstream cannot be re-filled:
454
455
 
456
457
std::istringstream iss(numerator);
458
iss >> m_num;
459
// this is not possible with istrstream
460
iss.clear();
461
iss.str(denominator);
462
iss >> m_den;
463
464
 
465
466
If you don't care about speed, you can put these conversions in
467
      a template-function:
468
469
470
template <class X>
471
void fromString(const string& input, X& any)
472
{
473
#ifdef HAVE_SSTREAM
474
std::istringstream iss(input);
475
#else
476
std::istrstream iss(input.c_str());
477
#endif
478
X temp;
479
iss >> temp;
480
if (iss.fail())
481
throw runtime_error(..)
482
any = temp;
483
}
484
485
 
486
487
  Another example of using stringstreams is in 
488
  linkend="strings.string.shrink">this howto.
489
490
 
491
 There is additional information in the libstdc++-v2 info files, in
492
particular info iostream.
493
494
495
 
496
497
  Little or no wide character support
498
  
499
    Classes wstring and
500
    char_traits<wchar_t> are
501
    not supported.
502
  
503
504
 
505
506
  No templatized iostreams
507
  
508
    Classes wfilebuf and
509
    wstringstream are not supported.
510
  
511
512
 
513
514
Thread safety issues
515
 
516
  
517
    Earlier GCC releases had a somewhat different approach to
518
    threading configuration and proper compilation.  Before GCC 3.0,
519
    configuration of the threading model was dictated by compiler
520
    command-line options and macros (both of which were somewhat
521
    thread-implementation and port-specific).  There were no
522
    guarantees related to being able to link code compiled with one
523
    set of options and macro setting with another set.
524
  
525
 
526
  
527
    For GCC 3.0, configuration of the threading model used with
528
    libraries and user-code is performed when GCC is configured and
529
    built using the --enable-threads and --disable-threads options.
530
    The ABI is stable for symbol name-mangling and limited functional
531
    compatibility exists between code compiled under different
532
    threading models.
533
  
534
 
535
   
536
     The libstdc++ library has been designed so that it can be used in
537
     multithreaded applications (with libstdc++-v2 this was only true
538
     of the STL parts.)  The first problem is finding a
539
     fast method of implementation portable to
540
     all platforms.  Due to historical reasons, some of the library is
541
     written against per-CPU-architecture spinlocks and other parts
542
     against the gthr.h abstraction layer which is provided by gcc.  A
543
     minor problem that pops up every so often is different
544
     interpretations of what "thread-safe" means for a
545
     library (not a general program).  We currently use the 
546
     url="http://www.sgi.com/tech/stl/thread_safety.html">same
547
     definition that SGI uses for their STL subset.  However,
548
     the exception for read-only containers only applies to the STL
549
     components. This definition is widely-used and something similar
550
     will be used in the next version of the C++ standard library.
551
   
552
 
553
   
554
     Here is a small link farm to threads (no pun) in the mail
555
     archives that discuss the threading problem.  Each link is to the
556
     first relevant message in the thread; from there you can use
557
     "Thread Next" to move down the thread.  This farm is in
558
     latest-to-oldest order.
559
   
560
 
561
      
562
        
563
          
564
            Our threading expert Loren gives a breakdown of 
565
            url="http://gcc.gnu.org/ml/libstdc++/2001-10/msg00024.html">the
566
            six situations involving threads for the 3.0
567
            release series.
568
          
569
      
570
        
571
          
572
            
573
        This message inspired a recent updating of issues with
574
        threading and the SGI STL library.  It also contains some
575
        example POSIX-multithreaded STL code.
576
          
577
        
578
      
579
 
580
   
581
     (A large selection of links to older messages has been removed;
582
     many of the messages from 1999 were lost in a disk crash, and the
583
     few people with access to the backup tapes have been too swamped
584
     with work to restore them.  Many of the points have been
585
     superseded anyhow.)
586
   
587
588
 
589
590
 
591
592
Third
593
 
594
 The third generation GNU C++ library is called libstdc++, or
595
libstdc++-v3.
596
597
 
598
      The subset commonly known as the Standard Template Library
599
         (chapters 23 through 25, mostly) is adapted from the final release
600
         of the SGI STL (version 3.3), with extensive changes.
601
      
602
 
603
      A more formal description of the V3 goals can be found in the
604
         official design document.
605
      
606
 
607
Portability notes and known implementation limitations are as follows.
608
 
609
610
Pre-ISO headers moved to backwards or removed
611
 
612
 The pre-ISO C++ headers
613
      (iostream.h, defalloc.h etc.) are
614
      available, unlike previous libstdc++ versions, but inclusion
615
      generates a warning that you are using deprecated headers.
616
617
 
618
    This compatibility layer is constructed by including the
619
    standard C++ headers, and injecting any items in
620
    std:: into the global namespace.
621
   
622
   For those of you new to ISO C++ (welcome, time travelers!), no,
623
      that isn't a typo. Yes, the headers really have new names.
624
      Marshall Cline's C++ FAQ Lite has a good explanation in item
625
      [27.4].
626
   
627
 
628
 Some include adjustment may be required. What follows is an
629
autoconf test that defines PRE_STDCXX_HEADERS when they
630
exist.
631
 
632
633
# AC_HEADER_PRE_STDCXX
634
AC_DEFUN([AC_HEADER_PRE_STDCXX], [
635
  AC_CACHE_CHECK(for pre-ISO C++ include files,
636
  ac_cv_cxx_pre_stdcxx,
637
  [AC_LANG_SAVE
638
  AC_LANG_CPLUSPLUS
639
  ac_save_CXXFLAGS="$CXXFLAGS"
640
  CXXFLAGS="$CXXFLAGS -Wno-deprecated"
641
 
642
  # Omit defalloc.h, as compilation with newer compilers is problematic.
643
  AC_TRY_COMPILE([
644
  #include <new.h>
645
  #include <iterator.h>
646
  #include <alloc.h>
647
  #include <set.h>
648
  #include <hashtable.h>
649
  #include <hash_set.h>
650
  #include <fstream.h>
651
  #include <tempbuf.h>
652
  #include <istream.h>
653
  #include <bvector.h>
654
  #include <stack.h>
655
  #include <rope.h>
656
  #include <complex.h>
657
  #include <ostream.h>
658
  #include <heap.h>
659
  #include <iostream.h>
660
  #include <function.h>
661
  #include <multimap.h>
662
  #include <pair.h>
663
  #include <stream.h>
664
  #include <iomanip.h>
665
  #include <slist.h>
666
  #include <tree.h>
667
  #include <vector.h>
668
  #include <deque.h>
669
  #include <multiset.h>
670
  #include <list.h>
671
  #include <map.h>
672
  #include <algobase.h>
673
  #include <hash_map.h>
674
  #include <algo.h>
675
  #include <queue.h>
676
  #include <streambuf.h>
677
  ],,
678
  ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
679
  CXXFLAGS="$ac_save_CXXFLAGS"
680
  AC_LANG_RESTORE
681
  ])
682
  if test "$ac_cv_cxx_pre_stdcxx" = yes; then
683
    AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
684
  fi
685
])
686
687
 
688
Porting between pre-ISO headers and ISO headers is simple: headers
689
like vector.h can be replaced with vector and a using
690
directive using namespace std; can be put at the global
691
scope. This should be enough to get this code compiling, assuming the
692
other usage is correct.
693
694
695
 
696
697
Extension headers hash_map, hash_set moved to ext or backwards
698
 
699
      At this time most of the features of the SGI STL extension have been
700
         replaced by standardized libraries.
701
         In particular, the unordered_map and unordered_set containers of TR1
702
         are suitable replacement for the non-standard hash_map and hash_set
703
         containers in the SGI STL.
704
      
705
 Header files hash_map and hash_set moved
706
to ext/hash_map and  ext/hash_set,
707
respectively. At the same time, all types in these files are enclosed
708
in namespace __gnu_cxx. Later versions move deprecate
709
these files, and suggest using TR1's  unordered_map
710
and  unordered_set instead.
711
712
 
713
      The extensions are no longer in the global or std
714
         namespaces, instead they are declared in the __gnu_cxx
715
         namespace. For maximum portability, consider defining a namespace
716
         alias to use to talk about extensions, e.g.:
717
      
718
      
719
      #ifdef __GNUC__
720
      #if __GNUC__ < 3
721
        #include <hash_map.h>
722
        namespace extension { using ::hash_map; }; // inherit globals
723
      #else
724
        #include <backward/hash_map>
725
        #if __GNUC__ == 3 && __GNUC_MINOR__ == 0
726
          namespace extension = std;               // GCC 3.0
727
        #else
728
          namespace extension = ::__gnu_cxx;       // GCC 3.1 and later
729
        #endif
730
      #endif
731
      #else      // ...  there are other compilers, right?
732
        namespace extension = std;
733
      #endif
734
 
735
      extension::hash_map<int,int> my_map;
736
      
737
      This is a bit cleaner than defining typedefs for all the
738
         instantiations you might need.
739
      
740
 
741
 
742
The following autoconf tests check for working HP/SGI hash containers.
743
744
 
745
746
# AC_HEADER_EXT_HASH_MAP
747
AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
748
  AC_CACHE_CHECK(for ext/hash_map,
749
  ac_cv_cxx_ext_hash_map,
750
  [AC_LANG_SAVE
751
  AC_LANG_CPLUSPLUS
752
  ac_save_CXXFLAGS="$CXXFLAGS"
753
  CXXFLAGS="$CXXFLAGS -Werror"
754
  AC_TRY_COMPILE([#include <ext/hash_map>], [using __gnu_cxx::hash_map;],
755
  ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
756
  CXXFLAGS="$ac_save_CXXFLAGS"
757
  AC_LANG_RESTORE
758
  ])
759
  if test "$ac_cv_cxx_ext_hash_map" = yes; then
760
    AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
761
  fi
762
])
763
764
 
765
766
# AC_HEADER_EXT_HASH_SET
767
AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
768
  AC_CACHE_CHECK(for ext/hash_set,
769
  ac_cv_cxx_ext_hash_set,
770
  [AC_LANG_SAVE
771
  AC_LANG_CPLUSPLUS
772
  ac_save_CXXFLAGS="$CXXFLAGS"
773
  CXXFLAGS="$CXXFLAGS -Werror"
774
  AC_TRY_COMPILE([#include <ext/hash_set>], [using __gnu_cxx::hash_set;],
775
  ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
776
  CXXFLAGS="$ac_save_CXXFLAGS"
777
  AC_LANG_RESTORE
778
  ])
779
  if test "$ac_cv_cxx_ext_hash_set" = yes; then
780
    AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
781
  fi
782
])
783
784
785
 
786
787
No <code>ios::nocreate/ios::noreplace</code>.</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>788</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
789
 
790
 The existence of ios::nocreate being used for
791
input-streams has been confirmed, most probably because the author
792
thought it would be more correct to specify nocreate explicitly.  So
793
it can be left out for input-streams.
794
795
 
796
For output streams, nocreate is probably the default,
797
unless you specify std::ios::trunc ? To be safe, you can
798
open the file for reading, check if it has been opened, and then
799
decide whether you want to create/replace or not. To my knowledge,
800
even older implementations support app, ate
801
and trunc (except for app ?).
802
803
804
 
805
806
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>807</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>No <code>stream::attach(int fd)</code></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>808</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
809
 
810
811
      Phil Edwards writes: It was considered and rejected for the ISO
812
      standard.  Not all environments use file descriptors.  Of those
813
      that do, not all of them use integers to represent them.
814
    
815
 
816
817
      For a portable solution (among systems which use
818
      file descriptors), you need to implement a subclass of
819
      std::streambuf (or
820
      std::basic_streambuf<..>) which opens a file
821
      given a descriptor, and then pass an instance of this to the
822
      stream-constructor.
823
    
824
 
825
826
      An extension is available that implements this.
827
      ext/stdio_filebuf.h contains a derived class called
828
      __gnu_cxx::stdio_filebuf.
829
      This class can be constructed from a C FILE* or a file
830
      descriptor, and provides the fd() function.
831
    
832
 
833
834
 For another example of this, refer to
835
      fdstream example
836
      by Nicolai Josuttis.
837
838
839
 
840
841
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>842</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>Support for C++98 dialect.</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>843</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
844
 
845
Check for complete library coverage of the C++1998/2003 standard.
846
847
 
848
849
# AC_HEADER_STDCXX_98
850
AC_DEFUN([AC_HEADER_STDCXX_98], [
851
  AC_CACHE_CHECK(for ISO C++ 98 include files,
852
  ac_cv_cxx_stdcxx_98,
853
  [AC_LANG_SAVE
854
  AC_LANG_CPLUSPLUS
855
  AC_TRY_COMPILE([
856
    #include <cassert>
857
    #include <cctype>
858
    #include <cerrno>
859
    #include <cfloat>
860
    #include <ciso646>
861
    #include <climits>
862
    #include <clocale>
863
    #include <cmath>
864
    #include <csetjmp>
865
    #include <csignal>
866
    #include <cstdarg>
867
    #include <cstddef>
868
    #include <cstdio>
869
    #include <cstdlib>
870
    #include <cstring>
871
    #include <ctime>
872
 
873
    #include <algorithm>
874
    #include <bitset>
875
    #include <complex>
876
    #include <deque>
877
    #include <exception>
878
    #include <fstream>
879
    #include <functional>
880
    #include <iomanip>
881
    #include <ios>
882
    #include <iosfwd>
883
    #include <iostream>
884
    #include <istream>
885
    #include <iterator>
886
    #include <limits>
887
    #include <list>
888
    #include <locale>
889
    #include <map>
890
    #include <memory>
891
    #include <new>
892
    #include <numeric>
893
    #include <ostream>
894
    #include <queue>
895
    #include <set>
896
    #include <sstream>
897
    #include <stack>
898
    #include <stdexcept>
899
    #include <streambuf>
900
    #include <string>
901
    #include <typeinfo>
902
    #include <utility>
903
    #include <valarray>
904
    #include <vector>
905
  ],,
906
  ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
907
  AC_LANG_RESTORE
908
  ])
909
  if test "$ac_cv_cxx_stdcxx_98" = yes; then
910
    AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
911
  fi
912
])
913
914
915
 
916
917
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>918</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>Support for C++TR1 dialect.</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>919</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
920
 
921
Check for library coverage of the TR1 standard.
922
923
 
924
925
# AC_HEADER_STDCXX_TR1
926
AC_DEFUN([AC_HEADER_STDCXX_TR1], [
927
  AC_CACHE_CHECK(for ISO C++ TR1 include files,
928
  ac_cv_cxx_stdcxx_tr1,
929
  [AC_LANG_SAVE
930
  AC_LANG_CPLUSPLUS
931
  AC_TRY_COMPILE([
932
  #include <tr1/array>
933
  #include <tr1/ccomplex>
934
  #include <tr1/cctype>
935
  #include <tr1/cfenv>
936
  #include <tr1/cfloat>
937
  #include <tr1/cinttypes>
938
  #include <tr1/climits>
939
  #include <tr1/cmath>
940
  #include <tr1/complex>
941
  #include <tr1/cstdarg>
942
  #include <tr1/cstdbool>
943
  #include <tr1/cstdint>
944
  #include <tr1/cstdio>
945
  #include <tr1/cstdlib>
946
  #include <tr1/ctgmath>
947
  #include <tr1/ctime>
948
  #include <tr1/cwchar>
949
  #include <tr1/cwctype>
950
  #include <tr1/functional>
951
  #include <tr1/memory>
952
  #include <tr1/random>
953
  #include <tr1/regex>
954
  #include <tr1/tuple>
955
  #include <tr1/type_traits>
956
  #include <tr1/unordered_set>
957
  #include <tr1/unordered_map>
958
  #include <tr1/utility>
959
  ],,
960
  ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
961
  AC_LANG_RESTORE
962
  ])
963
  if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
964
    AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
965
  fi
966
])
967
968
 
969
An alternative is to check just for specific TR1 includes, such as <unordered_map> and <unordered_set>.
970
971
 
972
973
# AC_HEADER_TR1_UNORDERED_MAP
974
AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
975
  AC_CACHE_CHECK(for tr1/unordered_map,
976
  ac_cv_cxx_tr1_unordered_map,
977
  [AC_LANG_SAVE
978
  AC_LANG_CPLUSPLUS
979
  AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;],
980
  ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
981
  AC_LANG_RESTORE
982
  ])
983
  if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
984
    AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
985
  fi
986
])
987
988
 
989
990
# AC_HEADER_TR1_UNORDERED_SET
991
AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
992
  AC_CACHE_CHECK(for tr1/unordered_set,
993
  ac_cv_cxx_tr1_unordered_set,
994
  [AC_LANG_SAVE
995
  AC_LANG_CPLUSPLUS
996
  AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;],
997
  ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
998
  AC_LANG_RESTORE
999
  ])
1000
  if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
1001
    AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
1002
  fi
1003
])
1004
1005
1006
 
1007
 
1008
1009
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1010</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>Support for C++0x dialect.</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1011</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
1012
 
1013
Check for baseline language coverage in the compiler for the C++0xstandard.
1014
1015
 
1016
1017
# AC_COMPILE_STDCXX_OX
1018
AC_DEFUN([AC_COMPILE_STDCXX_0X], [
1019
  AC_CACHE_CHECK(if g++ supports C++0x features without additional flags,
1020
  ac_cv_cxx_compile_cxx0x_native,
1021
  [AC_LANG_SAVE
1022
  AC_LANG_CPLUSPLUS
1023
  AC_TRY_COMPILE([
1024
  template <typename T>
1025
    struct check
1026
    {
1027
      static_assert(sizeof(int) <= sizeof(T), "not big enough");
1028
    };
1029
 
1030
    typedef check<check<bool>> right_angle_brackets;
1031
 
1032
    int a;
1033
    decltype(a) b;
1034
 
1035
    typedef check<int> check_type;
1036
    check_type c;
1037
    check_type&& cr = c;],,
1038
  ac_cv_cxx_compile_cxx0x_native=yes, ac_cv_cxx_compile_cxx0x_native=no)
1039
  AC_LANG_RESTORE
1040
  ])
1041
 
1042
  AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x,
1043
  ac_cv_cxx_compile_cxx0x_cxx,
1044
  [AC_LANG_SAVE
1045
  AC_LANG_CPLUSPLUS
1046
  ac_save_CXXFLAGS="$CXXFLAGS"
1047
  CXXFLAGS="$CXXFLAGS -std=c++0x"
1048
  AC_TRY_COMPILE([
1049
  template <typename T>
1050
    struct check
1051
    {
1052
      static_assert(sizeof(int) <= sizeof(T), "not big enough");
1053
    };
1054
 
1055
    typedef check<check<bool>> right_angle_brackets;
1056
 
1057
    int a;
1058
    decltype(a) b;
1059
 
1060
    typedef check<int> check_type;
1061
    check_type c;
1062
    check_type&& cr = c;],,
1063
  ac_cv_cxx_compile_cxx0x_cxx=yes, ac_cv_cxx_compile_cxx0x_cxx=no)
1064
  CXXFLAGS="$ac_save_CXXFLAGS"
1065
  AC_LANG_RESTORE
1066
  ])
1067
 
1068
  AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x,
1069
  ac_cv_cxx_compile_cxx0x_gxx,
1070
  [AC_LANG_SAVE
1071
  AC_LANG_CPLUSPLUS
1072
  ac_save_CXXFLAGS="$CXXFLAGS"
1073
  CXXFLAGS="$CXXFLAGS -std=gnu++0x"
1074
  AC_TRY_COMPILE([
1075
  template <typename T>
1076
    struct check
1077
    {
1078
      static_assert(sizeof(int) <= sizeof(T), "not big enough");
1079
    };
1080
 
1081
    typedef check<check<bool>> right_angle_brackets;
1082
 
1083
    int a;
1084
    decltype(a) b;
1085
 
1086
    typedef check<int> check_type;
1087
    check_type c;
1088
    check_type&& cr = c;],,
1089
  ac_cv_cxx_compile_cxx0x_gxx=yes, ac_cv_cxx_compile_cxx0x_gxx=no)
1090
  CXXFLAGS="$ac_save_CXXFLAGS"
1091
  AC_LANG_RESTORE
1092
  ])
1093
 
1094
  if test "$ac_cv_cxx_compile_cxx0x_native" = yes ||
1095
     test "$ac_cv_cxx_compile_cxx0x_cxx" = yes ||
1096
     test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then
1097
    AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ])
1098
  fi
1099
])
1100
1101
 
1102
 
1103
Check for library coverage of the C++0xstandard.
1104
1105
 
1106
1107
# AC_HEADER_STDCXX_0X
1108
AC_DEFUN([AC_HEADER_STDCXX_0X], [
1109
  AC_CACHE_CHECK(for ISO C++ 0x include files,
1110
  ac_cv_cxx_stdcxx_0x,
1111
  [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1112
  AC_LANG_SAVE
1113
  AC_LANG_CPLUSPLUS
1114
  ac_save_CXXFLAGS="$CXXFLAGS"
1115
  CXXFLAGS="$CXXFLAGS -std=gnu++0x"
1116
 
1117
  AC_TRY_COMPILE([
1118
    #include <cassert>
1119
    #include <ccomplex>
1120
    #include <cctype>
1121
    #include <cerrno>
1122
    #include <cfenv>
1123
    #include <cfloat>
1124
    #include <cinttypes>
1125
    #include <ciso646>
1126
    #include <climits>
1127
    #include <clocale>
1128
    #include <cmath>
1129
    #include <csetjmp>
1130
    #include <csignal>
1131
    #include <cstdarg>
1132
    #include <cstdbool>
1133
    #include <cstddef>
1134
    #include <cstdint>
1135
    #include <cstdio>
1136
    #include <cstdlib>
1137
    #include <cstring>
1138
    #include <ctgmath>
1139
    #include <ctime>
1140
    #include <cwchar>
1141
    #include <cwctype>
1142
 
1143
    #include <algorithm>
1144
    #include <array>
1145
    #include <bitset>
1146
    #include <complex>
1147
    #include <deque>
1148
    #include <exception>
1149
    #include <fstream>
1150
    #include <functional>
1151
    #include <iomanip>
1152
    #include <ios>
1153
    #include <iosfwd>
1154
    #include <iostream>
1155
    #include <istream>
1156
    #include <iterator>
1157
    #include <limits>
1158
    #include <list>
1159
    #include <locale>
1160
    #include <map>
1161
    #include <memory>
1162
    #include <new>
1163
    #include <numeric>
1164
    #include <ostream>
1165
    #include <queue>
1166
    #include <random>
1167
    #include <regex>
1168
    #include <set>
1169
    #include <sstream>
1170
    #include <stack>
1171
    #include <stdexcept>
1172
    #include <streambuf>
1173
    #include <string>
1174
    #include <tuple>
1175
    #include <typeinfo>
1176
    #include <type_traits>
1177
    #include <unordered_map>
1178
    #include <unordered_set>
1179
    #include <utility>
1180
    #include <valarray>
1181
    #include <vector>
1182
  ],,
1183
  ac_cv_cxx_stdcxx_0x=yes, ac_cv_cxx_stdcxx_0x=no)
1184
  AC_LANG_RESTORE
1185
  CXXFLAGS="$ac_save_CXXFLAGS"
1186
  ])
1187
  if test "$ac_cv_cxx_stdcxx_0x" = yes; then
1188
    AC_DEFINE(STDCXX_0X_HEADERS,,[Define if ISO C++ 0x header files are present. ])
1189
  fi
1190
])
1191
1192
 
1193
As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For <unordered_map>
1194
1195
 
1196
1197
# AC_HEADER_UNORDERED_MAP
1198
AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
1199
  AC_CACHE_CHECK(for unordered_map,
1200
  ac_cv_cxx_unordered_map,
1201
  [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1202
  AC_LANG_SAVE
1203
  AC_LANG_CPLUSPLUS
1204
  ac_save_CXXFLAGS="$CXXFLAGS"
1205
  CXXFLAGS="$CXXFLAGS -std=gnu++0x"
1206
  AC_TRY_COMPILE([#include <unordered_map>], [using std::unordered_map;],
1207
  ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
1208
  CXXFLAGS="$ac_save_CXXFLAGS"
1209
  AC_LANG_RESTORE
1210
  ])
1211
  if test "$ac_cv_cxx_unordered_map" = yes; then
1212
    AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
1213
  fi
1214
])
1215
1216
 
1217
1218
# AC_HEADER_UNORDERED_SET
1219
AC_DEFUN([AC_HEADER_UNORDERED_SET], [
1220
  AC_CACHE_CHECK(for unordered_set,
1221
  ac_cv_cxx_unordered_set,
1222
  [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1223
  AC_LANG_SAVE
1224
  AC_LANG_CPLUSPLUS
1225
  ac_save_CXXFLAGS="$CXXFLAGS"
1226
  CXXFLAGS="$CXXFLAGS -std=gnu++0x"
1227
  AC_TRY_COMPILE([#include <unordered_set>], [using std::unordered_set;],
1228
  ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
1229
  CXXFLAGS="$ac_save_CXXFLAGS"
1230
  AC_LANG_RESTORE
1231
  ])
1232
  if test "$ac_cv_cxx_unordered_set" = yes; then
1233
    AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
1234
  fi
1235
])
1236
1237
1238
 
1239
1240
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1241</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  Container::iterator_type is not necessarily Container::value_type*</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1242</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
1243
 
1244
1245
  This is a change in behavior from the previous version. Now, most
1246
  iterator_type typedefs in container classes are POD
1247
  objects, not value_type pointers.
1248
1249
1250
 
1251
1252
 
1253
1254
Bibliography
1255
 
1256
  
1257
    
1258
      
1259
        
1260
          Migrating to GCC 4.1
1261
        
1262
        
1263
    
1264
    
1265
      Dan
1266
      Kegel
1267
    
1268
  
1269
 
1270
  
1271
    
1272
      
1273
        
1274
          Building the Whole Debian Archive with GCC 4.1: A Summary
1275
        
1276
      
1277
    
1278
    
1279
      Martin
1280
      Michlmayr
1281
    
1282
  
1283
 
1284
  
1285
    
1286
      
1287
        
1288
          Migration guide for GCC-3.2
1289
        
1290
      
1291
    
1292
  
1293
 
1294
1295
 
1296

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.