关于 c :Preprocessor Errors Compiling Chrono_io

Preprocessor Errors Compiling Chrono_io

最近将一些代码拉到一个新系统中,我在编译 chrono_io 和 ratio_io 时遇到了一些问题。

我不确定要更改什么,因为错误似乎会影响预处理器。

看来这一定是代码没有考虑的跨平台兼容性问题。

有什么办法可以解决这些预处理器和编译器错误吗?

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
In file included from Test.cc:12:0:
chrono_io:221:18: error: missing binary operator before token"("
 #if __has_feature(cxx_rvalue_references)
                  ^
chrono_io:789:18: error: missing binary operator before token"("
 #if __has_feature(cxx_rvalue_references)
                  ^
chrono_io:821:18: error: missing binary operator before token"("
 #if __has_feature(cxx_rvalue_references)
                  ^
chrono_io:833:18: error: missing binary operator before token"("
 #if __has_feature(cxx_rvalue_references)
                  ^
chrono_io:845:18: error: missing binary operator before token"("
 #if __has_feature(cxx_rvalue_references)
                  ^
chrono_io:858:18: error: missing binary operator before token"("
 #if __has_feature(cxx_rvalue_references)
                  ^
chrono_io:885:18: error: missing binary operator before token"("
 #if __has_feature(cxx_rvalue_references)
                  ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:36:1: error: a€?_LIBCPP_BEGIN_NAMESPACE_STDa€? does not name a type
 _LIBCPP_BEGIN_NAMESPACE_STD
 ^
ratio_io:46:1: error: a€?basic_stringa€? does not name a type
 basic_string<_CharT>
 ^
ratio_io:58:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string
        ^
ratio_io:58:21: error: a€?attoa€? was not declared in this scope
 struct ratio_string
                     ^
ratio_io:58:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:513:47: note:   a€?std::attoa?
   typedef ratio<1,       1000000000000000000> atto;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:59:1: error: explicit specialization of non-template a€?ratio_stringa€?
 {
 ^
ratio_io:60:12: error: a€?stringa€? does not name a type
     static string symbol() {return string(1, 'a');}
            ^
ratio_io:61:12: error: a€?stringa€? does not name a type
     static string prefix()  {return string("atto");}
            ^
ratio_io:83:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string
        ^
ratio_io:83:21: error: a€?attoa€? was not declared in this scope
 struct ratio_string
                     ^
ratio_io:83:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:513:47: note:   a€?std::attoa?
   typedef ratio<1,       1000000000000000000> atto;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:83:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string
                                  ^
ratio_io:92:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<femto, char>
        ^
ratio_io:92:21: error: a€?femtoa€? was not declared in this scope
 struct ratio_string<femto, char>
                     ^
ratio_io:92:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:514:47: note:   a€?std::femtoa?
   typedef ratio<1,          1000000000000000> femto;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:92:32: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<femto, char>
                                ^
ratio_io:117:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<femto, wchar_t>
        ^
ratio_io:117:21: error: a€?femtoa€? was not declared in this scope
 struct ratio_string<femto, wchar_t>
                     ^
ratio_io:117:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:514:47: note:   a€?std::femtoa?
   typedef ratio<1,          1000000000000000> femto;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:117:35: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<femto, wchar_t>
                                   ^
ratio_io:126:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<pico, char>
        ^
ratio_io:126:21: error: a€?picoa€? was not declared in this scope
 struct ratio_string<pico, char>
                     ^
ratio_io:126:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:515:47: note:   a€?std::picoa?
   typedef ratio<1,             1000000000000> pico;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:126:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<pico, char>
                               ^
ratio_io:151:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<pico, wchar_t>
        ^
ratio_io:151:21: error: a€?picoa€? was not declared in this scope
 struct ratio_string<pico, wchar_t>
                     ^
ratio_io:151:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:515:47: note:   a€?std::picoa?
   typedef ratio<1,             1000000000000> pico;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:151:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<pico, wchar_t>
                                  ^
ratio_io:160:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<nano, char>
        ^
ratio_io:160:21: error: a€?nanoa€? was not declared in this scope
 struct ratio_string<nano, char>
                     ^
ratio_io:160:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:516:47: note:   a€?std::nanoa?
   typedef ratio<1,                1000000000> nano;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:160:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<nano, char>
                               ^
ratio_io:185:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<nano, wchar_t>
        ^
ratio_io:185:21: error: a€?nanoa€? was not declared in this scope
 struct ratio_string<nano, wchar_t>
                     ^
ratio_io:185:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:516:47: note:   a€?std::nanoa?
   typedef ratio<1,                1000000000> nano;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:185:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<nano, wchar_t>
                                  ^
ratio_io:194:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<micro, char>
        ^
ratio_io:194:21: error: a€?microa€? was not declared in this scope
 struct ratio_string<micro, char>
                     ^
ratio_io:194:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:517:47: note:   a€?std::microa?
   typedef ratio<1,                   1000000> micro;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:194:32: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<micro, char>
                                ^
ratio_io:219:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<micro, wchar_t>
        ^
ratio_io:219:21: error: a€?microa€? was not declared in this scope
 struct ratio_string<micro, wchar_t>
                     ^
ratio_io:219:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:517:47: note:   a€?std::microa?
   typedef ratio<1,                   1000000> micro;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:219:35: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<micro, wchar_t>
                                   ^
ratio_io:228:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<milli, char>
        ^
ratio_io:228:21: error: a€?millia€? was not declared in this scope
 struct ratio_string<milli, char>
                     ^
ratio_io:228:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:518:47: note:   a€?std::millia?
   typedef ratio<1,                      1000> milli;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:228:32: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<milli, char>
                                ^
ratio_io:253:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<milli, wchar_t>
        ^
ratio_io:253:21: error: a€?millia€? was not declared in this scope
 struct ratio_string<milli, wchar_t>
                     ^
ratio_io:253:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:518:47: note:   a€?std::millia?
   typedef ratio<1,                      1000> milli;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:253:35: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<milli, wchar_t>
                                   ^
ratio_io:262:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<centi, char>
        ^
ratio_io:262:21: error: a€?centia€? was not declared in this scope
 struct ratio_string<centi, char>
                     ^
ratio_io:262:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:519:47: note:   a€?std::centia?
   typedef ratio<1,                       100> centi;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:262:32: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<centi, char>
                                ^
ratio_io:287:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<centi, wchar_t>
        ^
ratio_io:287:21: error: a€?centia€? was not declared in this scope
 struct ratio_string<centi, wchar_t>
                     ^
ratio_io:287:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:519:47: note:   a€?std::centia?
   typedef ratio<1,                       100> centi;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:287:35: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<centi, wchar_t>
                                   ^
ratio_io:296:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<deci, char>
        ^
ratio_io:296:21: error: a€?decia€? was not declared in this scope
 struct ratio_string<deci, char>
                     ^
ratio_io:296:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:520:47: note:   a€?std::decia?
   typedef ratio<1,                        10> deci;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:296:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<deci, char>
                               ^
ratio_io:321:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<deci, wchar_t>
        ^
ratio_io:321:21: error: a€?decia€? was not declared in this scope
 struct ratio_string<deci, wchar_t>
                     ^
ratio_io:321:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:520:47: note:   a€?std::decia?
   typedef ratio<1,                        10> deci;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:321:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<deci, wchar_t>
                                  ^
ratio_io:330:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<deca, char>
        ^
ratio_io:330:21: error: a€?decaa€? was not declared in this scope
 struct ratio_string<deca, char>
                     ^
ratio_io:330:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:521:47: note:   a€?std::decaa?
   typedef ratio<                       10, 1> deca;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:330:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<deca, char>
                               ^
ratio_io:355:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<deca, wchar_t>
        ^
ratio_io:355:21: error: a€?decaa€? was not declared in this scope
 struct ratio_string<deca, wchar_t>
                     ^
ratio_io:355:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:521:47: note:   a€?std::decaa?
   typedef ratio<                       10, 1> deca;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:355:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<deca, wchar_t>
                                  ^
ratio_io:364:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<hecto, char>
        ^
ratio_io:364:21: error: a€?hectoa€? was not declared in this scope
 struct ratio_string<hecto, char>
                     ^
ratio_io:364:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:522:47: note:   a€?std::hectoa?
   typedef ratio<                      100, 1> hecto;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:364:32: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<hecto, char>
                                ^
ratio_io:389:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<hecto, wchar_t>
        ^
ratio_io:389:21: error: a€?hectoa€? was not declared in this scope
 struct ratio_string<hecto, wchar_t>
                     ^
ratio_io:389:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:522:47: note:   a€?std::hectoa?
   typedef ratio<                      100, 1> hecto;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:389:35: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<hecto, wchar_t>
                                   ^
ratio_io:398:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<kilo, char>
        ^
ratio_io:398:21: error: a€?kiloa€? was not declared in this scope
 struct ratio_string<kilo, char>
                     ^
ratio_io:398:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:523:47: note:   a€?std::kiloa?
   typedef ratio<                     1000, 1> kilo;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:398:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<kilo, char>
                               ^
ratio_io:423:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<kilo, wchar_t>
        ^
ratio_io:423:21: error: a€?kiloa€? was not declared in this scope
 struct ratio_string<kilo, wchar_t>
                     ^
ratio_io:423:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:523:47: note:   a€?std::kiloa?
   typedef ratio<                     1000, 1> kilo;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:423:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<kilo, wchar_t>
                                  ^
ratio_io:432:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<mega, char>
        ^
ratio_io:432:21: error: a€?megaa€? was not declared in this scope
 struct ratio_string<mega, char>
                     ^
ratio_io:432:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:524:47: note:   a€?std::megaa?
   typedef ratio<                  1000000, 1> mega;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:432:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<mega, char>
                               ^
ratio_io:457:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<mega, wchar_t>
        ^
ratio_io:457:21: error: a€?megaa€? was not declared in this scope
 struct ratio_string<mega, wchar_t>
                     ^
ratio_io:457:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:524:47: note:   a€?std::megaa?
   typedef ratio<                  1000000, 1> mega;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:457:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<mega, wchar_t>
                                  ^
ratio_io:466:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<giga, char>
        ^
ratio_io:466:21: error: a€?gigaa€? was not declared in this scope
 struct ratio_string<giga, char>
                     ^
ratio_io:466:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:525:47: note:   a€?std::gigaa?
   typedef ratio<               1000000000, 1> giga;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:466:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<giga, char>
                               ^
ratio_io:491:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<giga, wchar_t>
        ^
ratio_io:491:21: error: a€?gigaa€? was not declared in this scope
 struct ratio_string<giga, wchar_t>
                     ^
ratio_io:491:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:525:47: note:   a€?std::gigaa?
   typedef ratio<               1000000000, 1> giga;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:491:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<giga, wchar_t>
                                  ^
ratio_io:500:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<tera, char>
        ^
ratio_io:500:21: error: a€?teraa€? was not declared in this scope
 struct ratio_string<tera, char>
                     ^
ratio_io:500:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:526:47: note:   a€?std::teraa?
   typedef ratio<            1000000000000, 1> tera;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:500:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<tera, char>
                               ^
ratio_io:525:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<tera, wchar_t>
        ^
ratio_io:525:21: error: a€?teraa€? was not declared in this scope
 struct ratio_string<tera, wchar_t>
                     ^
ratio_io:525:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:526:47: note:   a€?std::teraa?
   typedef ratio<            1000000000000, 1> tera;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:525:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<tera, wchar_t>
                                  ^
ratio_io:534:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<peta, char>
        ^
ratio_io:534:21: error: a€?petaa€? was not declared in this scope
 struct ratio_string<peta, char>
                     ^
ratio_io:534:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:527:47: note:   a€?std::petaa?
   typedef ratio<         1000000000000000, 1> peta;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:534:31: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<peta, char>
                               ^
ratio_io:559:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<peta, wchar_t>
        ^
ratio_io:559:21: error: a€?petaa€? was not declared in this scope
 struct ratio_string<peta, wchar_t>
                     ^
ratio_io:559:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:527:47: note:   a€?std::petaa?
   typedef ratio<         1000000000000000, 1> peta;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:559:34: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<peta, wchar_t>
                                  ^
ratio_io:568:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<exa, char>
        ^
ratio_io:568:21: error: a€?exaa€? was not declared in this scope
 struct ratio_string<exa, char>
                     ^
ratio_io:568:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:528:47: note:   a€?std::exaa?
   typedef ratio<      1000000000000000000, 1> exa;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:568:30: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<exa, char>
                              ^
ratio_io:593:8: error: a€?ratio_stringa€? is not a class template
 struct ratio_string<exa, wchar_t>
        ^
ratio_io:593:21: error: a€?exaa€? was not declared in this scope
 struct ratio_string<exa, wchar_t>
                     ^
ratio_io:593:21: note: suggested alternative:
In file included from /usr/include/c++/4.8.2/chrono:38:0,
                 from Test.cc:11:
/usr/include/c++/4.8.2/ratio:528:47: note:   a€?std::exaa?
   typedef ratio<      1000000000000000000, 1> exa;
                                               ^
In file included from chrono_io:139:0,
                 from Test.cc:12:
ratio_io:593:33: error: a€?ratio_stringa€? is not a template type
 struct ratio_string<exa, wchar_t>
                                 ^
ratio_io:599:1: error: a€?_LIBCPP_END_NAMESPACE_STDa€? does not name a type
 _LIBCPP_END_NAMESPACE_STD
 ^
In file included from Test.cc:12:0:
chrono_io:1164:1: error: a€?_LIBCPP_END_NAMESPACE_STDa€? does not name a type
 _LIBCPP_END_NAMESPACE_STD
 ^
Test.cc: In function a€?void RealDataTest()a€?:
Test.cc:167:12: error: cannot bind a€?std::basic_ostream<char>a€? lvalue to a€?std::basic_ostream<char>&&a€?
  std::cout <<"Time for n->mostRecent:" << (Clock::now() - start) << std::endl;
            ^
In file included from /usr/include/c++/4.8.2/iostream:39:0,
                 from Nearby.cc:9,
                 from Test.cc:5:
/usr/include/c++/4.8.2/ostream:602:5: error:   initializing argument 1 of a€?std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::chrono::duration<long int, std::ratio<1l, 1000000000l> >]a€?
     operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
     ^
Test.cc:185:12: error: cannot bind a€?std::basic_ostream<char>a€? lvalue to a€?std::basic_ostream<char>&&a€?
  std::cout <<"Time for n->deletePost:" << (Clock::now() - start) << std::endl;
            ^
In file included from /usr/include/c++/4.8.2/iostream:39:0,
                 from Nearby.cc:9,
                 from Test.cc:5:
/usr/include/c++/4.8.2/ostream:602:5: error:   initializing argument 1 of a€?std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::chrono::duration<long int, std::ratio<1l, 1000000000l> >]a€?
     operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
     ^
make: *** [all] Error 1


我已经好几年没玩过这个代码了。它正在使用:

1
2
3
#if __has_feature(cxx_rvalue_references)
          __seconds_(std::move(__seconds)),
...

检查编译器是否支持右值引用(C 11 移动语义)。我的建议是假设您拥有 C 11(因为您必须拥有 <chrono> 并且只需删除 __has_feature#else 分支。

如果由于某种原因您必须支持没有右值引用的编译器,您可以:

1
#define __has_feature(x) 0

这将在任何地方选择 #else 分支。

__has_feature(cxx_rvalue_references) 是一个 clang 扩展。

更新

更新到这个库。

https://howardhinnant.github.io/date/chrono_io.html

已简化为仅流式传输持续时间。