File: trompeloeil.hpp

package info (click to toggle)
trompeloeil-cpp 43-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,540 kB
  • sloc: cpp: 15,524; sh: 114; makefile: 17
file content (5353 lines) | stat: -rw-r--r-- 161,062 bytes parent folder | download
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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
/*
 * Trompeloeil C++ mocking framework
 *
 * Copyright (C) Björn Fahller 2014-2021
 * Copyright (C) 2017, 2018 Andrew Paxie
 * Copyright Tore Martin Hagen 2019
 *
 *  Use, modification and distribution is subject to the
 *  Boost Software License, Version 1.0. (See accompanying
 *  file LICENSE_1_0.txt or copy at
 *  http://www.boost.org/LICENSE_1_0.txt)
 *
 * Project home: https://github.com/rollbear/trompeloeil
 */

#ifndef TROMPELOEIL_HPP_
#define TROMPELOEIL_HPP_


// trompe l'oeil noun    (Concise Encyclopedia)
// Style of representation in which a painted object is intended
// to deceive the viewer into believing it is the object itself...

// project home: https://github.com/rollbear/trompeloeil


// Deficiencies and missing features
// * Mocking function templates is not supported
// * If a macro kills a kitten, this threatens extinction of all felines!

#if defined(_MSC_VER)

#  define TROMPELOEIL_NORETURN __declspec(noreturn)

#  if (!defined(__cplusplus) || _MSC_VER < 1900)
#    error requires C++ in Visual Studio 2015 RC or later
#  endif

#else

#  define TROMPELOEIL_NORETURN [[noreturn]]

#  if (!defined(__cplusplus) || __cplusplus < 201103L)
#    error requires C++11 or higher
#  endif

#endif

#if defined(__clang__)

#  define TROMPELOEIL_CLANG 1
#  define TROMPELOEIL_GCC 0
#  define TROMPELOEIL_MSVC 0

#  define TROMPELOEIL_CLANG_VERSION \
  (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)

#  define TROMPELOEIL_GCC_VERSION 0

#  define TROMPELOEIL_CPLUSPLUS __cplusplus

#  define TROMPELOEIL_NOT_IMPLEMENTED(...)                         \
  _Pragma("clang diagnostic push")                                   \
  _Pragma("clang diagnostic ignored \"-Wunneeded-member-function\"") \
  __VA_ARGS__                                                        \
  _Pragma("clang diagnostic pop")

#elif defined(__GNUC__)

#  define TROMPELOEIL_CLANG 0
#  define TROMPELOEIL_GCC 1
#  define TROMPELOEIL_MSVC 0

#  define TROMPELOEIL_CLANG_VERSION 0
#  define TROMPELOEIL_GCC_VERSION \
  (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)

#  define TROMPELOEIL_CPLUSPLUS __cplusplus

#elif defined(_MSC_VER)

#  define TROMPELOEIL_CLANG 0
#  define TROMPELOEIL_GCC 0
#  define TROMPELOEIL_MSVC 1

#  define TROMPELOEIL_CLANG_VERSION 0
#  define TROMPELOEIL_GCC_VERSION 0

#  if defined(_MSVC_LANG)

    // Compiler is at least Microsoft Visual Studio 2015 Update 3.
#    define TROMPELOEIL_CPLUSPLUS _MSVC_LANG

#  else /* defined(_MSVC_LANG) */

    /*
     * This version of Microsoft Visual C++ is released
     * in a version of Microsoft Visual Studio between
     * 2015 RC and less than 2015 Update 3.
     *
     * It is an amalgam of C++ versions, with no provision
     * to specify C++11 mode.
     *
     * It also has a __cplusplus macro stuck at 199711L with
     * no way to change it, such as /Zc:__cplusplus.
     *
     * Assume the C++14 code path, but don't promise that it is a
     * fully conforming implementation of C++14 either.
     * Hence a value of 201401L, which less than 201402L,
     * the standards conforming value of __cplusplus.
     */
#    define TROMPELOEIL_CPLUSPLUS 201401L

#  endif /* !defined(_MSVC_LANG) */

#endif


#ifndef TROMPELOEIL_NOT_IMPLEMENTED
#define TROMPELOEIL_NOT_IMPLEMENTED(...) __VA_ARGS__
#endif

#include <tuple>
#include <iomanip>
#include <sstream>
#include <exception>
#include <functional>
#include <memory>
#include <cstring>
#include <regex>
#include <mutex>
#include <atomic>
#include <array>
#include <initializer_list>
#include <type_traits>
#include <utility>


#ifndef TROMPELOEIL_CUSTOM_ATOMIC
#include <atomic>
namespace trompeloeil { using std::atomic; }
#else
#include <trompeloeil/custom_atomic.hpp>
#endif

#ifndef TROMPELOEIL_CUSTOM_UNIQUE_LOCK
namespace trompeloeil { using std::unique_lock; }
#else
#include <trompeloeil/custom_unique_lock.hpp>
#endif

#ifdef TROMPELOEIL_SANITY_CHECKS
#include <cassert>
#define TROMPELOEIL_ASSERT(x) assert(x)
#else
#define TROMPELOEIL_ASSERT(x) do {} while (false)
#endif

#define TROMPELOEIL_IDENTITY(...) __VA_ARGS__ // work around stupid MS VS2015 RC bug

#define TROMPELOEIL_ARG16(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15, ...) _15

#define TROMPELOEIL_COUNT(...)                                                 \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_ARG16(__VA_ARGS__,                          \
                                         15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0))

#if TROMPELOEIL_MSVC

#define TROMPELOEIL_CONCAT_(x, y, ...) x ## y __VA_ARGS__
#define TROMPELOEIL_CONCAT(x, ...) TROMPELOEIL_CONCAT_(x, __VA_ARGS__)

#else /* TROMPELOEIL_MSVC */

#define TROMPELOEIL_CONCAT_(x, ...) x ## __VA_ARGS__
#define TROMPELOEIL_CONCAT(x, ...) TROMPELOEIL_CONCAT_(x, __VA_ARGS__)

#endif /* !TROMPELOEIL_MSVC */

#define TROMPELOEIL_SEPARATE1(p1) p1
#define TROMPELOEIL_SEPARATE2(p1,p2) p1 p2
#define TROMPELOEIL_SEPARATE3(p1,...) p1 TROMPELOEIL_SEPARATE2(__VA_ARGS__)
#define TROMPELOEIL_SEPARATE4(p1,...) p1 TROMPELOEIL_SEPARATE3(__VA_ARGS__)
#define TROMPELOEIL_SEPARATE5(p1,...) p1 TROMPELOEIL_SEPARATE4(__VA_ARGS__)
#define TROMPELOEIL_SEPARATE6(p1,...) p1 TROMPELOEIL_SEPARATE5(__VA_ARGS__)
#define TROMPELOEIL_SEPARATE7(p1,...) p1 TROMPELOEIL_SEPARATE6(__VA_ARGS__)
#define TROMPELOEIL_SEPARATE8(p1,...) p1 TROMPELOEIL_SEPARATE7(__VA_ARGS__)
#define TROMPELOEIL_SEPARATE9(p1,...) p1 TROMPELOEIL_SEPARATE8(__VA_ARGS__)
#define TROMPELOEIL_SEPARATE(...) \
  TROMPELOEIL_CONCAT(TROMPELOEIL_SEPARATE,\
                     TROMPELOEIL_COUNT(__VA_ARGS__))(__VA_ARGS__)


#define TROMPELOEIL_REMOVE_PAREN(...) TROMPELOEIL_CONCAT(TROMPELOEIL_CLEAR_,   \
  TROMPELOEIL_REMOVE_PAREN_INTERNAL __VA_ARGS__)
#define TROMPELOEIL_REMOVE_PAREN_INTERNAL(...)                                 \
  TROMPELOEIL_REMOVE_PAREN_INTERNAL __VA_ARGS__
#define TROMPELOEIL_CLEAR_TROMPELOEIL_REMOVE_PAREN_INTERNAL

#define TROMPELOEIL_INIT_WITH_STR15(base, x, ...)                              \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR14(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR14(base, x, ...)                              \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR13(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR13(base, x, ...)                              \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR12(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR12(base, x, ...)                              \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR11(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR11(base, x, ...)                              \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR10(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR10(base, x, ...)                              \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR9(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR9(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR8(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR8(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR7(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR7(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR6(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR6(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR5(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR5(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR4(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR4(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR3(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR3(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR2(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR2(base, x, ...)                               \
  base{#x, x}, TROMPELOEIL_INIT_WITH_STR1(base, __VA_ARGS__)

#define TROMPELOEIL_INIT_WITH_STR1(base, x)                                    \
  base{#x, x}

#define TROMPELOEIL_INIT_WITH_STR0(base)

#define TROMPELOEIL_INIT_WITH_STR(base, ...)                                   \
  TROMPELOEIL_CONCAT(TROMPELOEIL_INIT_WITH_STR,                                \
                     TROMPELOEIL_COUNT(__VA_ARGS__))(base, __VA_ARGS__)

#define TROMPELOEIL_PARAM_LIST15(...)                                          \
  TROMPELOEIL_PARAM_LIST14(__VA_ARGS__),                                       \
  ::trompeloeil::param_list_t<__VA_ARGS__, 14> p15

#define TROMPELOEIL_PARAM_LIST14(...)                                          \
  TROMPELOEIL_PARAM_LIST13(__VA_ARGS__),                                       \
  ::trompeloeil::param_list_t<__VA_ARGS__, 13> p14

#define TROMPELOEIL_PARAM_LIST13(...)                                          \
  TROMPELOEIL_PARAM_LIST12(__VA_ARGS__),                                       \
  ::trompeloeil::param_list_t<__VA_ARGS__, 12> p13

#define TROMPELOEIL_PARAM_LIST12(...)                                          \
  TROMPELOEIL_PARAM_LIST11(__VA_ARGS__),                                       \
  ::trompeloeil::param_list_t<__VA_ARGS__, 11> p12

#define TROMPELOEIL_PARAM_LIST11(...)                                          \
  TROMPELOEIL_PARAM_LIST10(__VA_ARGS__),                                       \
  ::trompeloeil::param_list_t<__VA_ARGS__, 10> p11

#define TROMPELOEIL_PARAM_LIST10(...)                                          \
  TROMPELOEIL_PARAM_LIST9(__VA_ARGS__),                                        \
  ::trompeloeil::param_list_t<__VA_ARGS__, 9> p10

#define TROMPELOEIL_PARAM_LIST9(...)                                           \
  TROMPELOEIL_PARAM_LIST8(__VA_ARGS__),                                        \
  ::trompeloeil::param_list_t<__VA_ARGS__, 8> p9

#define TROMPELOEIL_PARAM_LIST8(...)                                           \
  TROMPELOEIL_PARAM_LIST7(__VA_ARGS__),                                        \
  ::trompeloeil::param_list_t<__VA_ARGS__, 7> p8

#define TROMPELOEIL_PARAM_LIST7(...)                                           \
  TROMPELOEIL_PARAM_LIST6(__VA_ARGS__),                                        \
  ::trompeloeil::param_list_t<__VA_ARGS__, 6> p7

#define TROMPELOEIL_PARAM_LIST6(...)                                           \
  TROMPELOEIL_PARAM_LIST5(__VA_ARGS__),                                        \
  ::trompeloeil::param_list_t<__VA_ARGS__, 5> p6

#define TROMPELOEIL_PARAM_LIST5(...)                                           \
  TROMPELOEIL_PARAM_LIST4(__VA_ARGS__),                                        \
    ::trompeloeil::param_list_t<__VA_ARGS__, 4> p5

#define TROMPELOEIL_PARAM_LIST4(...)                                           \
  TROMPELOEIL_PARAM_LIST3(__VA_ARGS__),                                        \
    ::trompeloeil::param_list_t<__VA_ARGS__, 3> p4

#define TROMPELOEIL_PARAM_LIST3(...)                                           \
  TROMPELOEIL_PARAM_LIST2(__VA_ARGS__),                                        \
  ::trompeloeil::param_list_t<__VA_ARGS__, 2> p3

#define TROMPELOEIL_PARAM_LIST2(...)                                           \
  TROMPELOEIL_PARAM_LIST1(__VA_ARGS__),                                        \
  ::trompeloeil::param_list_t<__VA_ARGS__, 1> p2

#define TROMPELOEIL_PARAM_LIST1(...)                                           \
  ::trompeloeil::param_list_t<__VA_ARGS__, 0> p1

#define TROMPELOEIL_PARAM_LIST0(func_type)

#define TROMPELOEIL_PARAM_LIST(num, func_type)                                 \
  TROMPELOEIL_CONCAT(TROMPELOEIL_PARAM_LIST, num)                              \
    (TROMPELOEIL_REMOVE_PAREN(func_type))


#define TROMPELOEIL_PARAMS15 TROMPELOEIL_PARAMS14, p15
#define TROMPELOEIL_PARAMS14 TROMPELOEIL_PARAMS13, p14
#define TROMPELOEIL_PARAMS13 TROMPELOEIL_PARAMS12, p13
#define TROMPELOEIL_PARAMS12 TROMPELOEIL_PARAMS11, p12
#define TROMPELOEIL_PARAMS11 TROMPELOEIL_PARAMS10, p11
#define TROMPELOEIL_PARAMS10 TROMPELOEIL_PARAMS9,  p10
#define TROMPELOEIL_PARAMS9  TROMPELOEIL_PARAMS8,  p9
#define TROMPELOEIL_PARAMS8  TROMPELOEIL_PARAMS7,  p8
#define TROMPELOEIL_PARAMS7  TROMPELOEIL_PARAMS6,  p7
#define TROMPELOEIL_PARAMS6  TROMPELOEIL_PARAMS5,  p6
#define TROMPELOEIL_PARAMS5  TROMPELOEIL_PARAMS4,  p5
#define TROMPELOEIL_PARAMS4  TROMPELOEIL_PARAMS3,  p4
#define TROMPELOEIL_PARAMS3  TROMPELOEIL_PARAMS2,  p3
#define TROMPELOEIL_PARAMS2  TROMPELOEIL_PARAMS1,  p2
#define TROMPELOEIL_PARAMS1  ,                     p1
#define TROMPELOEIL_PARAMS0

#define TROMPELOEIL_PARAMS(num) TROMPELOEIL_CONCAT(TROMPELOEIL_PARAMS, num)

#if defined(__cxx_rtti) || defined(__GXX_RTTI) || defined(_CPPRTTI)
#  define TROMPELOEIL_TYPE_ID_NAME(x) typeid(x).name()
#else
#  define TROMPELOEIL_TYPE_ID_NAME(x) "object"
#endif

#if (TROMPELOEIL_CPLUSPLUS == 201103L)

#define TROMPELOEIL_DECLTYPE_AUTO \
  auto

#define TROMPELOEIL_TRAILING_RETURN_TYPE(return_type) \
  -> return_type

#else /* (TROMPELOEIL_CPLUSPLUS == 201103L) */

#define TROMPELOEIL_DECLTYPE_AUTO \
  decltype(auto)

#define TROMPELOEIL_TRAILING_RETURN_TYPE(return_type) \
  /**/

#endif /* !(TROMPELOEIL_CPLUSPLUS == 201103L) */
#if TROMPELOEIL_CPLUSPLUS > 201403L && (!TROMPELOEIL_GCC || TROMPELOEIL_GCC_VERSION >= 70000)
#  define TROMPELOEIL_INLINE_VAR [[maybe_unused]] static inline
#else
#  define TROMPELOEIL_INLINE_VAR static
#endif

static constexpr bool trompeloeil_movable_mock = false;

namespace trompeloeil
{
  template <typename T>
  struct identity_type
  {
    using type = T;
  };

  template <typename R, typename C, typename ... Args>
  identity_type<R(Args...)>
  nonconst_member_signature(R (C::*)(Args...))
  {
    return {};
  }

  template <typename R, typename C, typename ... Args>
  identity_type<R(Args...)>
  const_member_signature(R (C::*)(Args...) const)
  {
    return {};
  }

  template <typename ...>
  struct void_t_
  {
    using type = void;
  };

  template <typename ... T>
  using void_t = typename void_t_<T...>::type;

  template <template <typename ...> class, typename, typename ...>
  struct is_detected_{
    using type = std::false_type;
  };

  template <template <typename ...> class D, typename ... Ts>
  struct is_detected_<D, void_t<D<Ts...>>, Ts...>
  {
    using type = std::true_type;
  };

  template <template <typename ...> class D, typename ... Ts>
  using is_detected = typename is_detected_<D, void, Ts...>::type;

# if (TROMPELOEIL_CPLUSPLUS == 201103L)

  namespace detail
  {
    template <typename T>
    struct unwrap_type
    {
      using type = T;
    };
    template <typename T>
    struct unwrap_type<std::reference_wrapper<T>>
    {
      using type = T&;
    };
    template <typename ... Ts>
    std::tuple<typename unwrap_type<typename std::decay<Ts>::type>::type...>
    make_tuple(Ts&& ... ts)
    {
      return { std::forward<Ts>(ts)... };
    }

    /* Implement C++14 features using only C++11 entities. */

    /* <memory> */

    /* Implementation of make_unique is from
     *
     * Stephan T. Lavavej, "make_unique (Revision 1),"
     * ISO/IEC JTC1 SC22 WG21 N3656, 18 April 2013.
     * Available: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3656.htm
     * Accessed: 14 June 2017
     *
     * Renamed types to avoid the use of reserved identifiers.
     */
    template <class T>
    struct unique_if
    {
      typedef std::unique_ptr<T> single_object;
    };

    template <class T>
    struct unique_if<T[]>
    {
      typedef std::unique_ptr<T[]> unknown_bound;
    };

    template <class T, size_t N>
    struct unique_if<T[N]>
    {
      typedef void known_bound;
    };

    template <class T, class... Args>
    typename unique_if<T>::single_object
    make_unique(Args&&... args)
    {
      return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
    }

    template <class T>
    typename unique_if<T>::unknown_bound
    make_unique(size_t n)
    {
      typedef typename std::remove_extent<T>::type U;
      return std::unique_ptr<T>(new U[n]());
    }

    template <class T, class... Args>
    typename unique_if<T>::known_bound
    make_unique(Args&&...) = delete;

    /* <type_traits> */

    /* The implementation of these is from
     *
     * Walter E. Brown, "TransformationTraits Redux, v2,"
     * ISO/IEC JTC1 SC22 WG21 N3655, 18 April 2013.
     * Available: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3655.pdf
     * Accessed: 2 November 2017
     *
     * Minor changes to capitalize template parameter `bool B` has been made.
     *
     * See also:
     * http://en.cppreference.com/w/cpp/types/conditional
     * http://en.cppreference.com/w/cpp/types/decay
     * http://en.cppreference.com/w/cpp/types/enable_if
     * http://en.cppreference.com/w/cpp/types/remove_pointer
     * http://en.cppreference.com/w/cpp/types/remove_reference
     * Accessed: 17 May 2017
     */
    template <bool B, typename T, typename F>
    using conditional_t = typename std::conditional<B, T, F>::type;

    template <typename T>
    using decay_t = typename std::decay<T>::type;

    template <bool B, typename T = void>
    using enable_if_t = typename std::enable_if<B, T>::type;

    template <typename T>
    using remove_pointer_t = typename std::remove_pointer<T>::type;

    template <typename T>
    using remove_reference_t = typename std::remove_reference<T>::type;

    /* <utility> */

    /* This implementation of exchange is from
     *
     * Jeffrey Yasskin, "exchange() utility function, revision 3,"
     * ISO/IEC JTC1 SC22 WG21 N3688, 19 April 2013.
     * Available: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3668.html
     * Accessed: 2 November 2017
     *
     * See also:
     * http://en.cppreference.com/w/cpp/utility/exchange
     * Accessed: 17 May 2017
     */
    template<class T, class U = T>
    inline
    T
    exchange(
      T& obj,
      U&& new_value)
    {
      T old_value = std::move(obj);
      obj = std::forward<U>(new_value);
      return old_value;
    }

    /* integer_sequence and index_sequence implementations are from
     *
     * Jonathan Wakely, "Compile-time integer sequences,"
     * ISO/IEC JTC1 SC22 WG21 N3658, 18 April 2013.
     * Available: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html
     * Accessed: 2 November 2017
     *
     * See also:
     * http://en.cppreference.com/w/cpp/utility/integer_sequence
     * Accessed: 17 May 2017
     */
    template <typename T, T... I>
    struct integer_sequence
    {
      // Replaces a typedef used in the definition found in N3658.
      using value_type = T;

      static constexpr size_t size() noexcept
      {
          return sizeof...(I);
      }
    };

    template <size_t... I>
    using index_sequence = integer_sequence<size_t, I...>;

    /* This implementation of make_integer_sequence is from boost/mp11,
     *
     * Copyright 2015, 2017 Peter Dimov
     *
     * Distributed under the Boost Software License, Version 1.0.
     *
     * Implemented here:
     *
     * https://github.com/pdimov/mp11/blob/master/include/boost/
     *   integer_sequence.hpp
     * Accessed: 17 May 2017
     *
     * (now missing) and here:
     *
     * https://github.com/boostorg/mp11/blob/develop/include/boost/
     *   mp11/integer_sequence.hpp
     * Accessed: 13 August 2017
     */
    namespace impl
    {
      // iseq_if_c
      template <bool C, class T, class E>
      struct iseq_if_c_impl;

      template <class T, class E>
      struct iseq_if_c_impl<true, T, E>
      {
        using type = T;
      };

      template <class T, class E>
      struct iseq_if_c_impl<false, T, E>
      {
        using type = E;
      };

      template <bool C, class T, class E>
      using iseq_if_c = typename iseq_if_c_impl<C, T, E>::type;

      // iseq_identity
      template <class T>
      struct iseq_identity
      {
        using type = T;
      };

      template <class S1, class S2>
      struct append_integer_sequence;

      template <class T, T... I, T... J>
      struct append_integer_sequence<integer_sequence<T, I...>, integer_sequence<T, J...>>
      {
        using type = integer_sequence<T, I..., ( J + sizeof...(I) )...>;
      };

      template <class T, T N>
      struct make_integer_sequence_impl;

      template <class T, T N>
      struct make_integer_sequence_impl_
      {
      private:

        static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );

        static T const M = N / 2;
        static T const R = N % 2;

        using S1 = typename make_integer_sequence_impl<T, M>::type;
        using S2 = typename append_integer_sequence<S1, S1>::type;
        using S3 = typename make_integer_sequence_impl<T, R>::type;
        using S4 = typename append_integer_sequence<S2, S3>::type;

      public:

        using type = S4;
      };

      template <class T, T N>
      struct make_integer_sequence_impl:
        iseq_if_c<N == 0,
          iseq_identity<integer_sequence<T>>,
          iseq_if_c<N == 1,
            iseq_identity<integer_sequence<T, 0>>,
            make_integer_sequence_impl_<T, N>>>
      {
      };
    }

    template<class T, T N>
    using make_integer_sequence = typename impl::make_integer_sequence_impl<T, N>::type;

    template <size_t N>
    using make_index_sequence = make_integer_sequence<size_t, N>;

    template <typename... T>
    using index_sequence_for = make_index_sequence<sizeof...(T)>;

  } /* namespace detail */

# else /* (TROMPELOEIL_CPLUSPLUS == 201103L) */

  /* Only these entities really need to
   * be available in namespace detail, but
   * VS 2015 has a problem with this approach.
   *
   *  namespace detail {
   *
   *  using std::make_unique;
   *
   *  using std::conditional_t;
   *  using std::decay_t;
   *  using std::enable_if_t;
   *  using std::remove_pointer_t;
   *  using std::remove_reference_t;
   *
   *  using std::exchange;
   *  using std::index_sequence;
   *  using std::index_sequence_for;
   *  using std::integer_sequence;
   *  using std::make_index_sequence;
   *
   *  }
   *
   * Instead, use a namespace alias.
   */
  namespace detail = std;

# endif /* !(TROMPELOEIL_CPLUSPLUS == 201103L) */

# if TROMPELOEIL_CPLUSPLUS >= 201703L
#   if TROMPELOEIL_CLANG && TROMPELOEIL_CLANG_VERSION >= 60000

  // these are mostly added to work around clang++ bugs
  // https://bugs.llvm.org/show_bug.cgi?id=38033
  // https://bugs.llvm.org/show_bug.cgi?id=38010

  template <typename T>
  using move_construct_type = decltype(T(std::declval<T&&>()));

  template <typename T>
  using copy_construct_type = decltype(T(std::declval<const T&>()));

  template <typename T>
  using can_move_construct = is_detected<move_construct_type, detail::decay_t<T>>;

  template <typename T>
  using can_copy_construct = is_detected<copy_construct_type, detail::decay_t<T>>;

#   else
  template <typename T>
  using can_move_construct = std::is_move_constructible<T>;

  template <typename T>
  using can_copy_construct = std::is_copy_constructible<T>;
#   endif

  template <typename F, typename ... A>
  using invoke_result_type = decltype(std::declval<F&>()(std::declval<A>()...));

# else

  template <typename T>
  using can_move_construct = std::is_move_constructible<T>;

  template <typename T>
  using can_copy_construct = std::is_copy_constructible<T>;

  template <typename F, typename ... A>
  using invoke_result_type = decltype(std::declval<F&>()(std::declval<A>()...));

# endif

  class specialized;

  template <typename T>
  using aligned_storage_for =
    typename std::aligned_storage<sizeof(T), alignof(T)>::type;

#ifndef TROMPELOEIL_CUSTOM_RECURSIVE_MUTEX

  template <typename T = void>
  unique_lock<std::recursive_mutex> get_lock()
  {
    // Ugly hack for lifetime of mutex. The statically allocated
    // recursive_mutex is intentionally leaked, to ensure that the
    // mutex is available and valid even if the last use is from
    // the destructor of a global object in a translation unit
    // without #include <trompeloeil.hpp>

    static aligned_storage_for<std::recursive_mutex> buffer;
    static auto mutex = new (&buffer) std::recursive_mutex;
    return unique_lock<std::recursive_mutex>{*mutex};
  }

#else

  class custom_recursive_mutex {
  public:
    virtual ~custom_recursive_mutex() = default;
    virtual void lock() = 0;
    virtual void unlock() = 0;
  };

  // User has to provide an own recursive mutex.
  std::unique_ptr<custom_recursive_mutex> create_custom_recursive_mutex();

  template <typename T = void>
  unique_lock<custom_recursive_mutex> get_lock()
  {
    static std::unique_ptr<custom_recursive_mutex> mtx =
        create_custom_recursive_mutex();
    return unique_lock<custom_recursive_mutex>{*mtx};
  }

#endif

  template <size_t N, typename T>
  using conditional_tuple_element
    = detail::conditional_t<(N < std::tuple_size<T>::value),
                         typename std::tuple_element<N, T>::type,
                         int>;

  template <typename T>
  struct param_list;

  template <typename R, typename ... P>
  struct param_list<R(P...)>
  {
    static size_t constexpr const size = sizeof...(P);
    template <size_t N>
    using type = conditional_tuple_element<N, std::tuple<P...>>;
  };

  template <typename Sig, size_t N>
  using param_list_t = typename param_list<Sig>::template type<N>;

  class expectation_violation : public std::logic_error
  {
  public:
    using std::logic_error::logic_error;
  };

  struct location
  {
    location()
    noexcept
      : file("")
      , line(0U)
    {}

    location(
      char const* file_,
      unsigned long line_
    )
    noexcept
      : file{file_}
      , line{line_}
    {}

    char const *file;
    unsigned long line;
  };

  inline
  std::ostream&
  operator<<(
    std::ostream& os,
    const location& loc)
  {
    if (loc.line != 0U) os << loc.file << ':' << loc.line;
    return os;
  }

  enum class severity { fatal, nonfatal };

  using reporter_func = std::function<void(severity,
                                           char const *file,
                                           unsigned long line,
                                           std::string const &msg)>;

  using ok_reporter_func = std::function<void(char const *msg)>;

  inline
  void
  default_reporter(
    severity,
    char const *file,
    unsigned long line,
    std::string const &msg)
  {
    if (!std::current_exception())
    {
      std::stringstream os;
      os << location{ file, line } << "\n" << msg;
      throw expectation_violation(os.str());
    }
  }

  inline
  void
  default_ok_reporter(char const* /*msg*/)
  {
    /* OK reporter defaults to doing nothing. */
  }

  inline
  reporter_func&
  reporter_obj()
  {
    static reporter_func obj = default_reporter;
    return obj;
  }

  inline
  ok_reporter_func&
  ok_reporter_obj()
  {
    static ok_reporter_func obj = default_ok_reporter;
    return obj;
  }

  inline
  reporter_func
  set_reporter(
    reporter_func f)
  {
    return detail::exchange(reporter_obj(), std::move(f));
  }

  inline
  std::pair<reporter_func, ok_reporter_func>
  set_reporter(
    reporter_func rf,
    ok_reporter_func orf)
  {
    return {
      set_reporter(std::move(rf)),
      detail::exchange(ok_reporter_obj(), std::move(orf))
    };
  }

  class tracer;

  inline
  tracer*&
  tracer_obj()
  noexcept
  {
    static tracer* ptr = nullptr;
    return ptr;
  }

  inline
  tracer*
  set_tracer(
    tracer* obj)
  noexcept
  {
    // std::exchange would be sane here, but it costs compilation time
    auto& ptr = tracer_obj();
    auto rv = ptr;
    ptr = obj;
    return rv;
  }

  class tracer
  {
  public:
    virtual
    void
    trace(
      char const *file,
      unsigned long line,
      std::string const &call) = 0;
  protected:
    tracer() = default;
    tracer(tracer const&) = delete;
    tracer& operator=(tracer const&) = delete;
    virtual
    ~tracer()
    {
      set_tracer(previous);
    }
  private:
    tracer* previous = set_tracer(this);
  };

  class stream_tracer : public tracer
  {
  public:
    explicit
    stream_tracer(
      std::ostream& stream_)
      : stream(stream_) {}
    void
    trace(
      char const *file,
      unsigned long line,
      std::string const &call)
      override
    {
      stream << location{file, line} << '\n' << call << '\n';
    }
  private:
    std::ostream& stream;
  };

  class trace_agent;

  template <typename T>
  struct reporter;

  template <typename T>
  void
  send_report(
    severity s,
    location loc,
    std::string const &msg)
  {
    reporter<T>::send(s, loc.file, loc.line, msg.c_str());
  }

  template <typename T>
  void
  send_ok_report(
    std::string const &msg)
  {
    reporter<T>::sendOk(msg.c_str());
  }

  template <typename T>
  struct reporter
  {
    static
    void
    send(
      severity s,
      char const *file,
      unsigned long line,
      char const *msg);

    static
    void
    sendOk(
      char const *msg);

  };

  template <typename T>
  void reporter<T>::
    send(
      severity s,
      char const *file,
      unsigned long line,
      char const *msg)
    {
      reporter_obj()(s, file, line, msg);
    }

  template <typename T>
  void reporter<T>::
    sendOk(char const* msg)
    {
      ok_reporter_obj()(msg);
    }

  template <typename ... T>
  constexpr
  bool
  ignore(
    T const& ...)
  noexcept
  {
    return true;
  }

  struct illegal_argument
  {
    template <bool b = false>
    constexpr
    illegal_argument const& operator&() const
    {
      static_assert(b, "illegal argument");
      return *this;
    }

    template <bool b = false>
    constexpr
    illegal_argument const& operator*() const
    {
      static_assert(b, "illegal argument");
      return *this;
    }

    template <typename T, bool b = false>
    constexpr
    illegal_argument const& operator=(T const&) const
    {
      static_assert(b, "illegal argument");
      return *this;
    }

    template <typename T, bool b = false>
    constexpr
    operator T() const
    {
      static_assert(b, "illegal argument");
      return {};
    }
  };

  struct matcher { };

  struct wildcard : public matcher
  {
    template <typename T
#if TROMPELOEIL_GCC && TROMPELOEIL_GCC_VERSION >= 50000
              ,detail::enable_if_t<!std::is_convertible<wildcard&, T>{}>* = nullptr
#endif
              >
    operator T&&()
    const;

    template <typename T
#if TROMPELOEIL_GCC && TROMPELOEIL_GCC_VERSION >= 50000
              ,detail::enable_if_t<!std::is_convertible<wildcard&, T>{}>* = nullptr
#endif
              >
    operator T&()
    volatile const; // less preferred than T&& above

    template <typename T>
    constexpr
    bool
    matches(
      T const&)
    const
    noexcept
    {
      return true;
    }
  };

  TROMPELOEIL_INLINE_VAR wildcard _{};

template <typename T>
  using matcher_access = decltype(static_cast<matcher*>(std::declval<typename std::add_pointer<T>::type>()));

  template <typename T>
  using is_matcher = typename is_detected<matcher_access, T>::type;

  template <typename T>
  struct typed_matcher : matcher
  {
    operator T() const { return {}; }
  };

  template <>
  struct typed_matcher<std::nullptr_t> : matcher
  {
    template <typename T, typename = decltype(std::declval<T>() == nullptr)>
    operator T&&() const;

    template <typename T,
              typename = decltype(std::declval<T>() == nullptr)>
    operator T&()const volatile;

    template <typename T, typename C>
    operator T C::*() const;
  };

  template <typename Pred, typename ... T>
  class duck_typed_matcher : public matcher
  {
  public:
#if (!TROMPELOEIL_GCC) || \
    (TROMPELOEIL_GCC && TROMPELOEIL_GCC_VERSION >= 40900)

    // g++ 4.8 gives a "conversion from <T> to <U> is ambiguous" error
    // if this operator is defined.
    template <typename V,
              typename = detail::enable_if_t<!is_matcher<V>{}>,
              typename = invoke_result_type<Pred, V&&, T...>>
    operator V&&() const {
#if !TROMPELOEIL_CLANG || TROMPELOEIL_CLANG_VERSION >= 40000
      // clang 3.x instantiates the function even when it's only used
      // for compile time signature checks and never actually called.
      static_assert(std::is_same<V, void>{},
                    "Conversion function must only be used in unevaluated context for SFINAE expressions.\n"
                    "The matcher conversion is used in a runtime context.\n"
                    "See https://github.com/rollbear/trompeloeil/issues/270");
#endif
      return *this;
    }

#endif

    template <typename V,
              typename = detail::enable_if_t<!is_matcher<V>{}>,
              typename = invoke_result_type<Pred, V&, T...>>
    operator V&() const volatile;
  };

  template <typename T>
  using ostream_insertion = decltype(std::declval<std::ostream&>() << std::declval<T>());

  template <typename T>
  using is_output_streamable = std::integral_constant<bool, is_detected<ostream_insertion, T>::value && !std::is_array<T>::value>;

  struct stream_sentry
  {
    explicit
    stream_sentry(
      std::ostream& os_)
      : os(os_)
      , width(os.width(0))
      , flags(os.flags(std::ios_base::dec | std::ios_base::left))
      , fill(os.fill(' '))
      {  }
      stream_sentry(
        stream_sentry const&)
      = delete;
    ~stream_sentry()
    {
      os.flags(flags);
      os.fill(fill);
      os.width(width);
    }
  private:
    std::ostream& os;
    std::streamsize width;
    std::ios_base::fmtflags flags;
    char fill;
  };

  struct indirect_null {
#if !TROMPELOEIL_CLANG
    template <
      typename T,
      typename = detail::enable_if_t<std::is_convertible<std::nullptr_t, T>::value>
    >
    operator T&&() const = delete;
#endif
#if TROMPELOEIL_GCC || TROMPELOEIL_MSVC

    template <typename T, typename C, typename ... As>
    using memfunptr = T (C::*)(As...);

    template <typename T>
    operator T*() const;
    template <typename T, typename C>
    operator T C::*() const;
    template <typename T, typename C, typename ... As>
    operator memfunptr<T,C,As...>() const;
#endif /* TROMPELOEIL_GCC || TROMPELOEIL_MSVC */
    operator std::nullptr_t() const;
  };

  template <typename T, typename U>
  using equality_comparison = decltype((std::declval<T const&>() == std::declval<U const&>())
                                       ? true
                                       : false);

  template <typename T, typename U>
  using is_equal_comparable = is_detected<equality_comparison, T, U>;

#if defined(_MSC_VER) && (_MSC_VER < 1910)
  template <typename T>
  using is_null_comparable = is_equal_comparable<T, std::nullptr_t>;
#else
  template <typename T>
  using is_null_comparable = is_equal_comparable<T, indirect_null>;
#endif

  template <typename T, typename = decltype(std::declval<T const&>() == nullptr)>
  constexpr
  auto
  is_null_redirect(
    T const &t)
  noexcept(noexcept(std::declval<T const&>() == nullptr))
  -> decltype(t == nullptr)
  {
    return t == nullptr;
  }

  template <typename T>
  constexpr
  auto
  is_null(
    T const &t,
    std::true_type)
  noexcept(noexcept(is_null_redirect(t)))
  -> decltype(is_null_redirect(t))
  {
    // Redirect evaluation to suppress wrong non-null warnings in g++ 9 and 10.
    return is_null_redirect(t);
  }

  template <typename T, typename V>
  constexpr
  bool
  is_null(
    T const &,
    V)
  noexcept
  {
    return false;
  }

  template <typename T>
  constexpr
  bool
  is_null(
    T const &,
    std::false_type)
  noexcept
  {
    return false;
  }

  template <typename T>
  constexpr
  bool
  is_null(
    T const &t)
  {
    // g++-4.9 uses C++11 rules for constexpr function, so can't
    // break this up into smaller bits
    using tag = std::integral_constant<bool, is_null_comparable<T>::value
                                       && !is_matcher<T>::value
                                       && !std::is_array<T>::value>;

    return ::trompeloeil::is_null(t, tag{});
  }

  template <typename T>
  void
  print(
    std::ostream& os,
    T const &t);

  template <typename T>
  using iterable = decltype(std::begin(std::declval<T&>()) == std::end(std::declval<T&>()));

  template <typename T>
  using is_collection = is_detected<iterable, T>;

  template <typename T,
            bool = is_output_streamable<T>::value,
            bool = is_collection<detail::remove_reference_t<T>>::value>
  struct streamer
  {
    static
    void
    print(
      std::ostream& os,
      T const &t)
    {
      stream_sentry s(os);
      os << t;
    }
  };

  template <typename ... T>
  struct streamer<std::tuple<T...>, false, false>
  {
    static
    void
    print(
      std::ostream& os,
      std::tuple<T...> const&  t)
    {
      print_tuple(os, t, detail::index_sequence_for<T...>{});
    }
    template <size_t ... I>
    static
    void
    print_tuple(
      std::ostream& os,
      std::tuple<T...> const& t,
      detail::index_sequence<I...>)
    {
      os << "{ ";
      const char* sep = "";
      std::initializer_list<const char*> v{((os << sep),
                                            ::trompeloeil::print(os, std::get<I>(t)),
                                            (sep = ", "))...};
      ignore(v);
      os << " }";
    }
  };

  template <typename T, typename U>
  struct streamer<std::pair<T, U>, false, false>
  {
    static
    void
    print(
      std::ostream& os,
      std::pair<T, U> const& t)
    {
      os << "{ ";
      ::trompeloeil::print(os, t.first);
      os << ", ";
      ::trompeloeil::print(os, t.second);
      os << " }";
    }
  };

  template <typename T>
  struct streamer<T, false, true>
  {
    static
    void
    print(
      std::ostream& os,
      T const& t)
    {
      os << "{ ";
      const char* sep = "";
      auto const end = std::end(t);
      for (auto i = std::begin(t); i != end; ++i)
      {
        os << sep;
        ::trompeloeil::print(os, *i);
        sep = ", ";
      }
      os << " }";
    }
  };

  template <typename T>
  struct streamer<T, false, false>
  {
    static
    void
    print(
      std::ostream& os,
      T const &t)
    {
      stream_sentry s(os);
      static const char *linebreak = "\n";
      os << sizeof(T) << "-byte object={";
      os << (linebreak + (sizeof(T) <= 8)); // stupid construction silences VS2015 warning
      os << std::setfill('0') << std::hex;
      auto p = reinterpret_cast<uint8_t const*>(&t);
      for (size_t i = 0; i < sizeof(T); ++i)
      {
        os << " 0x" << std::setw(2) << std::right << unsigned(p[i]);
        if ((i & 0xf) == 0xf) os << '\n';
      }
      os << " }";
    }
  };

  template <typename T, typename = void>
  struct printer
  {
    static
    void
    print(
      std::ostream& os,
      T const & t)
    {
      streamer<T>::print(os, t);
    }
  };

  template <>
  struct printer<wildcard>
  {
    static
    void
    print(
	  std::ostream& os,
	  wildcard const&)
    {
      os << " matching _";
    }
  };
  template <typename T>
  void
  print(
    std::ostream& os,
    T const &t)
  {
    if (is_null(t))
    {
      os << "nullptr";
    }
    else
    {
      printer<T>::print(os, t);
    }
  }

  inline
  void
  print(
      std::ostream& os,
      std::nullptr_t)
  {
    os << "nullptr";
  }

  constexpr
  auto
  param_compare_operator(
    void const*)
  TROMPELOEIL_TRAILING_RETURN_TYPE(const char*)
  {
    return " == ";
  }

  constexpr
  auto
  param_compare_operator(
    matcher const*)
  TROMPELOEIL_TRAILING_RETURN_TYPE(const char*)
  {
    return "";
  }

  template <typename T>
  void
  print_expectation(
    std::ostream& os,
    T const& t)
  {
    os << param_compare_operator(&t);
    print(os, t);
    os << '\n';
  }

  template <typename T>
  class list_elem
  {
  public:
    list_elem(
      const list_elem&)
    = delete;

    list_elem(
      list_elem &&r)
    noexcept
    {
      *this = std::move(r);
    }

    list_elem&
    operator=(
      list_elem &&r)
    noexcept
    {
      if (this != &r)
      {
        next = r.next;
        prev = &r;
        r.invariant_check();

        next->prev = this;
        r.next = this;

        TROMPELOEIL_ASSERT(next->prev == this);
        TROMPELOEIL_ASSERT(prev->next == this);

        r.unlink();

        TROMPELOEIL_ASSERT(!r.is_linked());
        invariant_check();
      }
      return *this;
    }

    list_elem&
    operator=(
      const list_elem&)
    = delete;

    virtual
    ~list_elem()
    {
      unlink();
    }

    void
    unlink()
    noexcept
    {
      invariant_check();
      auto n = next;
      auto p = prev;
      n->prev = p;
      p->next = n;
      next = this;
      prev = this;
      invariant_check();
    }

    void
    invariant_check()
    const
    noexcept
    {
#ifdef TROMPELOEIL_SANITY_CHECKS
      TROMPELOEIL_ASSERT(next->prev == this);
      TROMPELOEIL_ASSERT(prev->next == this);
      TROMPELOEIL_ASSERT((next == this) == (prev == this));
      TROMPELOEIL_ASSERT((prev->next == next) == (next == this));
      TROMPELOEIL_ASSERT((next->prev == prev) == (prev == this));
      auto pp = prev;
      auto nn = next;
      do {
        TROMPELOEIL_ASSERT((nn == this) == (pp == this));
        TROMPELOEIL_ASSERT(nn->next->prev == nn);
        TROMPELOEIL_ASSERT(nn->prev->next == nn);
        TROMPELOEIL_ASSERT(pp->next->prev == pp);
        TROMPELOEIL_ASSERT(pp->prev->next == pp);
        TROMPELOEIL_ASSERT((nn->next == nn) == (nn == this));
        TROMPELOEIL_ASSERT((pp->prev == pp) == (pp == this));
        nn = nn->next;
        pp = pp->prev;
      } while (nn != this);
#endif
    }

    bool
    is_linked()
    const
    noexcept
    {
      invariant_check();
      return next != this;
    }
  protected:
    list_elem() noexcept = default;
  public:
    list_elem* next = this;
    list_elem* prev = this;
  };

  class ignore_disposer
  {
  protected:
    template <typename T>
    TROMPELOEIL_NORETURN
    void
    dispose(
      T*)
    const
    noexcept
    {
      std::abort(); // must never be called
    }
  };

  class delete_disposer
  {
  protected:
    template <typename T>
    void
    dispose(
      T* t)
    const
    {
      delete t;
    }
  };

  template <typename T, typename Disposer = ignore_disposer>
  class list : private list_elem<T>, private Disposer
  {
  public:
    list() noexcept;
    list(list&&) noexcept;
    list(const list&) = delete;
    list& operator=(list&&) noexcept;
    list& operator=(const list&) = delete;
    ~list() override;
    class iterator;
    iterator begin() const noexcept;
    iterator end() const noexcept;
    iterator push_front(T* t) noexcept;
    iterator push_back(T* t) noexcept;
    bool empty() const noexcept { return begin() == end(); }
  private:
    using list_elem<T>::invariant_check;
    using list_elem<T>::next;
    using list_elem<T>::prev;
  };

  template <typename T, typename Disposer>
  class list<T, Disposer>::iterator
  {
    friend class list<T, Disposer>;
    using iterator_category = std::bidirectional_iterator_tag;
    using value_type = T;
    using difference_type = std::ptrdiff_t;
    using pointer = T*;
    using reference = T&;
  public:
    friend
    bool
    operator==(
      iterator const &lh,
      iterator const &rh)
    noexcept
    {
      return lh.p == rh.p;
    }

    friend
    bool
    operator!=(
      iterator const &lh,
      iterator const &rh)
    noexcept
    {
      return !(lh == rh);
    }

    iterator&
    operator++()
    noexcept
    {
      p = p->next;
      return *this;
    }

    iterator
    operator++(int)
    noexcept
    {
      auto rv = *this;
      operator++();
      return rv;
    }

    T&
    operator*()
    noexcept
    {
      return static_cast<T&>(*p);
    }

    T*
    operator->()
    noexcept
    {
      return static_cast<T*>(p);
    }

  private:
    explicit
    iterator(
      list_elem<T> const *t)
    noexcept
    : p{const_cast<list_elem<T>*>(t)}
    {}

    list_elem<T>* p = nullptr;
  };

  template <typename T, typename Disposer>
  list<T, Disposer>::list() noexcept = default;

  template <typename T, typename Disposer>
  list<T, Disposer>::list(list&&) noexcept = default;

  template <typename T, typename Disposer>
  list<T, Disposer>& list<T, Disposer>::operator=(list&&) noexcept = default;

  template <typename T, typename Disposer>
  list<T, Disposer>::~list()
  {
    auto i = this->begin();
    while (i != this->end())
    {
      auto& elem = *i;
      ++i; // intrusive list, so advance before destroying
      Disposer::dispose(&elem);
    }
  }

  template <typename T, typename Disposer>
  auto
  list<T, Disposer>::begin()
  const
  noexcept
  -> iterator
  {
    return iterator{next};
  }

  template <typename T, typename Disposer>
  auto
  list<T, Disposer>::end()
  const
  noexcept
  -> iterator
  {
    return iterator{this};
  }

  template <typename T, typename Disposer>
  auto
  list<T, Disposer>::push_front(
    T* t)
  noexcept
  -> iterator
  {
    invariant_check();
    t->next = next;
    t->prev = this;
    next->prev = t;
    next = t;
    invariant_check();
    return iterator{t};
  }

  template <typename T, typename Disposer>
  auto
  list<T, Disposer>::push_back(
    T* t)
  noexcept
  -> iterator
  {
    invariant_check();
    t->prev = prev;
    t->next = this;
    prev->next = t;
    prev = t;
    invariant_check();
    return iterator{t};
  }

  class sequence_matcher;

  class sequence_type
  {
  public:
    sequence_type() noexcept = default;
    sequence_type(sequence_type&&) noexcept = delete;
    sequence_type(const sequence_type&) = delete;
    sequence_type& operator=(sequence_type&&) noexcept = delete;
    sequence_type& operator=(const sequence_type&) = delete;
    ~sequence_type();

    bool
    is_completed()
    const
    noexcept;

    bool
    is_first(
      sequence_matcher const *m)
    const
    noexcept;

    unsigned
    cost(
      sequence_matcher const *m)
    const
    noexcept;

    void
    retire_until(
      sequence_matcher const* m)
    noexcept;

    void
    add_last(
      sequence_matcher *m)
    noexcept;

    void
    validate_match(
      severity s,
      sequence_matcher const *matcher,
      char const *seq_name,
      char const *match_name,
      location loc)
    const;

  private:
    list<sequence_matcher> matchers;
  };

  class sequence
  {
  public:
    sequence_type& operator*() { return *obj; }
    bool is_completed() const { return obj->is_completed(); }
  private:
    std::unique_ptr<sequence_type> obj{detail::make_unique<sequence_type>()};
  };

  struct sequence_handler_base;

  class sequence_matcher : public list_elem<sequence_matcher>
  {
  public:
    using init_type = std::pair<char const*, sequence&>;

    sequence_matcher(
      char const *exp,
      location loc,
      const sequence_handler_base& handler,
      init_type i)
    noexcept
    : seq_name(i.first)
    , exp_name(exp)
    , exp_loc(loc)
    , sequence_handler(handler)
    , seq(*i.second)
    {
      auto lock = get_lock();
      seq.add_last(this);
    }

    void
    validate_match(
      severity s,
      char const *match_name,
      location loc)
    const
    {
      seq.validate_match(s, this, seq_name, match_name, loc);
    }

    unsigned
    cost()
    const
    noexcept
    {
      return seq.cost(this);
    }

    bool
    is_satisfied()
      const
      noexcept;

    void
    retire()
    noexcept
    {
      this->unlink();
    }

    void
    retire_predecessors()
    noexcept
    {
      seq.retire_until(this);
    }

    void
    print_expectation(std::ostream& os)
    const
    {
      os << exp_name << " at " << exp_loc;
    }

    char const*
    sequence_name()
    const
    noexcept
    {
      return seq_name;
    }
  private:
    char const *seq_name;
    char const *exp_name;
    location    exp_loc;
    const sequence_handler_base& sequence_handler;
    sequence_type& seq;
  };

  inline
  bool
  sequence_type::is_completed()
  const
  noexcept
  {
    for (const auto& matcher : matchers)
    {
      if (!matcher.is_satisfied())
      {
        return false;
      }
    }
    return true;
  }

  inline
  bool
  sequence_type::is_first(
    sequence_matcher const *m)
  const
  noexcept
  {
    return !matchers.empty() && &*matchers.begin() == m;
  }

  inline
  unsigned
  sequence_type::cost(
    sequence_matcher const* m)
  const
  noexcept
  {
    unsigned sequence_cost = 0U;
    for (auto const& e : matchers)
    {
      if (&e == m) return sequence_cost;
      if (!e.is_satisfied())
      {
        return ~0U;
      }
      ++sequence_cost;
    }
    return ~0U;
  }

  inline
  void
  sequence_type::retire_until(
    sequence_matcher const* m)
  noexcept
  {
    while (!matchers.empty())
    {
      auto first = &*matchers.begin();
      if (first == m) return;
      first->retire();
    }
  }

  inline
  void
  sequence_type::validate_match(
    severity s,
    sequence_matcher const *matcher,
    char const* seq_name,
    char const* match_name,
    location loc)
  const
  {
    if (is_first(matcher)) return;
    if (matchers.empty())
    {
      std::ostringstream os;
      os << "Sequence mismatch for sequence \"" << seq_name
         << "\" with matching call of " << match_name
         << " at " << loc
         << ". Sequence \"" << seq_name
         << "\" has no more pending expectations\n";
      send_report<specialized>(s, loc, os.str());
    }
    for (auto const& m : matchers)
    {
      std::ostringstream os;
      os << "Sequence mismatch for sequence \"" << seq_name
         << "\" with matching call of " << match_name
         << " at " << loc
         << ". Sequence \"" << seq_name << "\" has ";
      m.print_expectation(os);
      os << " first in line\n";
      send_report<specialized>(s, loc, os.str());
    }
  }

  inline
  sequence_type::~sequence_type()
  {
    bool touched = false;
    std::ostringstream os;
    while (!matchers.empty())
    {
      auto m = matchers.begin();
      if (!touched)
      {
        os << "Sequence expectations not met at destruction of sequence object \""
           << m->sequence_name() << "\":";
        touched = true;
      }
      os << "\n  missing ";
      m->print_expectation(os);
      m->unlink();
    }
    if (touched)
    {
      os << "\n";
      send_report<specialized>(severity::nonfatal, location{}, os.str());
    }
  }

  inline
  void
  sequence_type::add_last(
    sequence_matcher *m)
  noexcept
  {
    matchers.push_back(m);
  }

  template <typename T>
  void can_match_parameter(T&);

  template <typename T>
  void can_match_parameter(T&&);

  template <typename M>
  class ptr_deref : public matcher
  {
  public:
    template <typename U,
              typename = decltype(can_match_parameter<detail::remove_reference_t<decltype(*std::declval<U>())>>(std::declval<M>()))>
    operator U() const;

    template <typename U>
    explicit
    ptr_deref(
      U&& m_)
      : m( std::forward<U>(m_) )
    {}

    template <typename U>
    bool
    matches(
      const U& u)
    const
    noexcept(noexcept(std::declval<M>().matches(*u)))
    {
      return (u != nullptr) && m.matches(*u);
    }

    friend
    std::ostream&
    operator<<(
      std::ostream& os,
      ptr_deref<M> const& p)
    {
      return os << p.m;
    }
  private:
    M m;
  };

  template <typename M>
  class neg_matcher : public matcher
  {
  public:
    template <typename U,
              typename = decltype(can_match_parameter<detail::remove_reference_t<decltype(std::declval<U>())>>(std::declval<M>()))>
    operator U() const { return {}; }

    template <typename U>
    explicit
    neg_matcher(
      U&& m_)
      : m( std::forward<U>(m_) )
    {}

    template <typename U>
    bool
    matches(
      const U& u)
    const
    noexcept(noexcept(!std::declval<M>().matches(u)))
    {
      return !m.matches(u);
    }

    friend
    std::ostream&
    operator<<(
      std::ostream& os,
      neg_matcher<M> const& p)
    {
      return os << p.m;
    }
  private:
    M m;
  };

  template <typename MatchType, typename Predicate, typename ... ActualType>
  struct matcher_kind
  {
    using type = typed_matcher<MatchType>;
  };

  template <typename Predicate, typename ... ActualType>
  struct matcher_kind<wildcard, Predicate, ActualType...>
  {
    using type = duck_typed_matcher<Predicate, ActualType...>;
  };

  template <typename MatchType, typename Predicate, typename ... ActualType>
  using matcher_kind_t =
    typename matcher_kind<MatchType, Predicate, ActualType...>::type;

  template <typename Predicate, typename Printer, typename MatcherType, typename ... T>
  class predicate_matcher
    : private Predicate
    , private Printer
    , public MatcherType
  {
  public:
    template <typename ... U>
    constexpr
    predicate_matcher(
      Predicate&& pred,
      Printer&& printer,
      U&& ... v)
      noexcept(noexcept(std::tuple<T...>(std::declval<U>()...)) && noexcept(Predicate(std::declval<Predicate&&>())) && noexcept(Printer(std::declval<Printer&&>())))
      : Predicate(std::move(pred))
      , Printer(std::move(printer))
      , value(std::forward<U>(v)...)
    {}

    template <typename V>
    constexpr
    bool
    matches(
      V&& v)
      const
      noexcept(noexcept(std::declval<Predicate const&>()(std::declval<V&&>(), std::declval<const T&>()...)))
    {
      return matches_(std::forward<V>(v), detail::make_index_sequence<sizeof...(T)>{});
    }

    friend
    std::ostream&
    operator<<(
      std::ostream& os,
      predicate_matcher const& v)
    {
      return v.print_(os, detail::make_index_sequence<sizeof...(T)>{});
    }
  private:
    // The below function call operator must be declared to
    // work around gcc bug 78446
    //
    // For some reason microsoft compiler from VS2015 update 3
    // requires the function call operator to be private to avoid
    // ambiguities.
    template <typename ... U>
    void operator()(U&&...) const = delete;

    template <typename V, size_t ... I>
    bool matches_(V&& v, detail::index_sequence<I...>) const
    {
      return Predicate::operator()(std::forward<V>(v), std::get<I>(value)...);
    }

    template <size_t ... I>
    std::ostream& print_(std::ostream& os_, detail::index_sequence<I...>) const
    {
      Printer::operator()(os_, std::get<I>(value)...);
      return os_;
    }

    std::tuple<T...> value;
  };

  template <typename MatchType, typename Predicate, typename Printer, typename ... T>
  using make_matcher_return =
    predicate_matcher<Predicate,
      Printer,
      matcher_kind_t<MatchType, Predicate, detail::decay_t<T>...>,
      detail::decay_t<T>...>;

  namespace lambdas {

    struct any_predicate
    {
      template <typename T>
      bool
      operator()(
        T&&)
      const
      {
        return true;
      }
    };

    // The below must be classes/structs to work with VS 2015 update 3
    // since it doesn't respect the trailing return type declaration on
    // the lambdas of template deduction context

    #define TROMPELOEIL_MK_PRED_BINOP(name, op)                         \
    struct name {                                                       \
      template <typename X, typename Y>                                 \
      auto operator()(X const& x, Y const& y) const -> decltype(x op y) \
      {                                                                 \
        ::trompeloeil::ignore(x,y);                                     \
        return x op y;                                                  \
      }                                                                 \
    }
    TROMPELOEIL_MK_PRED_BINOP(equal, ==);
    TROMPELOEIL_MK_PRED_BINOP(not_equal, !=);
    TROMPELOEIL_MK_PRED_BINOP(less, <);
    TROMPELOEIL_MK_PRED_BINOP(less_equal, <=);
    TROMPELOEIL_MK_PRED_BINOP(greater, >);
    TROMPELOEIL_MK_PRED_BINOP(greater_equal, >=);
    #undef TROMPELOEIL_MK_PRED_BINOP

    // Define `struct` with `operator()` to replace generic lambdas.

    struct any_printer
    {
      explicit
      any_printer(
        char const* type_name_)
        : type_name(type_name_)
      {}

      void
      operator()(
        std::ostream& os)
      const
      {
        os << " matching ANY(" << type_name << ")";
      }

    private:
      char const* type_name;
    };

    // These structures replace the `op` printer lambdas.

    #define TROMPELOEIL_MK_OP_PRINTER(name, op_string)                  \
    struct name ## _printer                                             \
    {                                                                   \
      template <typename T>                                             \
      void                                                              \
      operator()(                                                       \
        std::ostream& os,                                               \
        T const& value)                                                 \
      const                                                             \
      {                                                                 \
        os << op_string;                                                \
        ::trompeloeil::print(os, value);                                \
      }                                                                 \
    }
    TROMPELOEIL_MK_OP_PRINTER(equal, " == ");
    TROMPELOEIL_MK_OP_PRINTER(not_equal, " != ");
    TROMPELOEIL_MK_OP_PRINTER(less, " < ");
    TROMPELOEIL_MK_OP_PRINTER(less_equal, " <= ");
    TROMPELOEIL_MK_OP_PRINTER(greater, " > ");
    TROMPELOEIL_MK_OP_PRINTER(greater_equal, " >= ");
    #undef TROMPELOEIL_MK_OP_PRINTER

  }

  template <typename MatchType, typename Predicate, typename Printer, typename ... T>
  inline
  make_matcher_return<MatchType, Predicate, Printer, T...>
  make_matcher(Predicate pred, Printer print, T&& ... t)
  {
    return {std::move(pred), std::move(print), std::forward<T>(t)...};
  }


  template <
    typename T,
    typename R = make_matcher_return<T, lambdas::any_predicate, lambdas::any_printer>>
  inline
  auto
  any_matcher_impl(char const* type_name, std::false_type)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<T>(lambdas::any_predicate(), lambdas::any_printer(type_name));
  }

  template <typename T>
  wildcard
  any_matcher_impl(char const*, std::true_type);

  template <typename T>
  inline
  auto
  any_matcher(char const* name)
  TROMPELOEIL_TRAILING_RETURN_TYPE(decltype(any_matcher_impl<T>(name, std::is_array<T>{})))
  {
    static_assert(!std::is_array<T>::value,
                  "array parameter type decays to pointer type for ANY()"
                  " matcher. Please rephrase as pointer instead");
    return any_matcher_impl<T>(name, std::is_array<T>{});
  }
  template <
    typename T = wildcard,
    typename V,
    typename R = make_matcher_return<T, lambdas::equal, lambdas::equal_printer, V>>
  inline
  auto
  eq(
    V&& v)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<T>(lambdas::equal(),
                           lambdas::equal_printer(),
                           std::forward<V>(v));
  }

  template <
    typename T = wildcard,
    typename V,
    typename R = make_matcher_return<T, lambdas::not_equal, lambdas::not_equal_printer, V>>
  inline
  auto
  ne(
    V&& v)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<T>(lambdas::not_equal(),
                           lambdas::not_equal_printer(),
                           std::forward<V>(v));
  }

  template <
    typename T = wildcard,
    typename V,
    typename R = make_matcher_return<T, lambdas::greater_equal, lambdas::greater_equal_printer, V>>
  inline
  auto
  ge(
    V&& v)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<T>(lambdas::greater_equal(),
                           lambdas::greater_equal_printer(),
                           std::forward<V>(v));
  }

  template <
    typename T = wildcard,
    typename V,
    typename R = make_matcher_return<T, lambdas::greater, lambdas::greater_printer, V>>
  inline
  auto
  gt(
    V&& v)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<T>(lambdas::greater(),
                           lambdas::greater_printer(),
                           std::forward<V>(v));
  }

  template <
    typename T = wildcard,
    typename V,
    typename R = make_matcher_return<T, lambdas::less, lambdas::less_printer, V>>
  inline
  auto
  lt(
    V&& v)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<T>(lambdas::less(),
                           lambdas::less_printer(),
                           std::forward<V>(v));
  }

  template <
    typename T = wildcard,
    typename V,
    typename R = make_matcher_return<T, lambdas::less_equal, lambdas::less_equal_printer,  V>>
  inline
  auto
  le(
    V&& v)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<T>(lambdas::less_equal(),
                           lambdas::less_equal_printer(),
                           std::forward<V>(v));
  }

  namespace lambdas {

    struct regex_check
    {

      class string_helper // a vastly simplified string_view type of class
      {
      public:
        string_helper(
          std::string const& s)
        noexcept
          : str(s.c_str())
        {}

        constexpr
        string_helper(
          char const* s)
        noexcept
          : str(s)
        {}

        char const*
        c_str()
          const
          noexcept
        {
          return str;
        }
      private:
        char const* str;
      };

      regex_check(
        std::regex&& re_,
        std::regex_constants::match_flag_type match_type_)
        : re(std::move(re_)),
          match_type(match_type_)
      {}

      template <typename T>
      bool
      operator()(
        string_helper str,
        T const&)
      const
      {
          return str.c_str()
                 && std::regex_search(str.c_str(), re, match_type);
      }

    private:
      std::regex re;
      std::regex_constants::match_flag_type match_type;
    };

    struct regex_printer
    {
      template <typename T>
      void
      operator()(
        std::ostream& os,
        T const& str)
      const
      {
        os << " matching regular expression /" << str << "/";
      }
    };
  }

  template <
    typename Kind = wildcard,
    typename R = make_matcher_return<Kind, lambdas::regex_check, lambdas::regex_printer, std::string&&>>
  auto
  re(
    std::string s,
    std::regex_constants::syntax_option_type opt = std::regex_constants::ECMAScript,
    std::regex_constants::match_flag_type match_type = std::regex_constants::match_default)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<Kind>(lambdas::regex_check(std::regex(s, opt),
                                                   match_type),
                              lambdas::regex_printer(),
                              std::move(s));
  }

  template <
    typename Kind = wildcard,
    typename R = make_matcher_return<Kind, lambdas::regex_check, lambdas::regex_printer, std::string&&>>
  auto
  re(
    std::string s,
    std::regex_constants::match_flag_type match_type)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return make_matcher<Kind>(lambdas::regex_check(std::regex(s), match_type),
                              lambdas::regex_printer(),
                              std::move(s));
  }

  inline
  std::string
  param_name_prefix(
    void const*)
  {
    return "";
  }

  template <typename M>
  std::string
  param_name_prefix(
    const ptr_deref<M>*)
  {
    return "*" + ::trompeloeil::param_name_prefix(static_cast<M*>(nullptr));
  }

  template <typename M>
  std::string
  param_name_prefix(
    const neg_matcher<M>*)
  {
    return "not " + ::trompeloeil::param_name_prefix(static_cast<M*>(nullptr));
  }

  template <typename T>
  struct null_on_move
  {
  public:
    null_on_move()
    noexcept
    = default;

    null_on_move(
      null_on_move&&)
    noexcept
    {}

    null_on_move(
      null_on_move const&)
    noexcept
    {}

    ~null_on_move()
    = default;

    null_on_move&
    operator=(
      const null_on_move&)
    noexcept
    {
      p = nullptr;
      return *this;
    }

    null_on_move&
    operator=(
      null_on_move&&)
    noexcept
    {
      p = nullptr;
      return *this;
    }

    null_on_move&
    operator=(
      T* t)
    noexcept
    {
      p = t;
      return *this;
    }

    T*&
    leak()
    noexcept
    {
      return p;
    }

    T&
    operator*()
    const
    noexcept
    {
      return *p;
    }

    T*
    operator->()
    const
    noexcept
    {
      return p;
    }

    explicit
    operator bool()
    const
    noexcept
    {
      return p != nullptr;
    }
  private:
    T* p = nullptr;
  };

  struct sequence_handler_base
  {
  private:
    size_t min_calls{1};
    size_t max_calls{1};
    size_t call_count{0};
  public:

    virtual
    ~sequence_handler_base()
    noexcept = default;

    void
      increment_call()
      noexcept
    {
      ++call_count;
    }
    bool
      is_satisfied()
      const
      noexcept
    {
      return call_count >= min_calls;
    }

    bool
      is_saturated()
      const
      noexcept
    {
      return call_count == max_calls;
    }

    bool
      is_forbidden()
      const
      noexcept
    {
      return max_calls == 0ULL;
    }

    void
    set_limits(size_t L, size_t H)
      noexcept
    {
      min_calls = L;
      max_calls = H;
    }

    size_t
    get_min_calls()
      const
      noexcept
    {
      return min_calls;
    }

    size_t
      get_calls()
      const
      noexcept
    {
      return call_count;
    }

    virtual
    void
      validate(severity s, char const *, location) = 0;

    virtual
    bool
    can_be_called()
    const
    noexcept = 0;

    virtual
    unsigned
    order()
    const
    noexcept = 0;

    virtual
    void
      retire()
      noexcept = 0;

    virtual
    void
    retire_predecessors()
    noexcept = 0;
  protected:
    sequence_handler_base() = default;
    sequence_handler_base(const sequence_handler_base&) = default;
  };

  inline
  bool
  sequence_matcher::is_satisfied()
  const
  noexcept
  {
    return sequence_handler.is_satisfied();
  }

  template <size_t N>
  struct sequence_handler : public sequence_handler_base
  {
  public:
    template <size_t M = N, typename detail::enable_if_t<M == 0>* = nullptr>
    sequence_handler()
      noexcept
    {}

    template <typename ... S>
    sequence_handler(
      const sequence_handler_base& base,
      char const *name,
      location loc,
      S&& ... s)
    noexcept
      : sequence_handler_base(base)
      , matchers{{sequence_matcher{name, loc, *this, std::forward<S>(s)}...}}
    {
    }

    void
    validate(
      severity s,
      char const *match_name,
      location loc)
    override
    {
      for (auto& e : matchers)
      {
        e.validate_match(s, match_name, loc);
      }
    }

    unsigned
    order()
    const
    noexcept
    override
    {
      unsigned highest_order = 0U;
      for (auto& m : matchers)
      {
        auto cost = m.cost();
        if (cost > highest_order)
        {
          highest_order = cost;
        }
      }
      return highest_order;
    }

    bool
    can_be_called()
    const
    noexcept
    override
    {
      return order() != ~0U;
    }

    void
    retire()
    noexcept
    override
    {
      for (auto& e : matchers)
      {
        e.retire();
      }
    }

    void
    retire_predecessors()
    noexcept
      override
    {
      for (auto& e : matchers)
      {
        e.retire_predecessors();
      }
    }
  private:
    // work around for MS STL issue 942
    // https://github.com/microsoft/STL/issues/942
    detail::conditional_t<N == 0,
                          std::vector<sequence_matcher>,
                          std::array<sequence_matcher, N>> matchers;
  };

  struct lifetime_monitor;

  template <typename T>
  class deathwatched : public T
  {
    static_assert(std::has_virtual_destructor<T>::value,
                  "virtual destructor is a necessity for deathwatched to work");
  public:
    template <typename ... U,
              typename = detail::enable_if_t<std::is_constructible<T,U...>::value>>
    deathwatched(
      U&& ...u)
    noexcept(noexcept(T(std::declval<U>()...)))
      : T(std::forward<U>(u)...)
    {}

    ~deathwatched() override;

    trompeloeil::lifetime_monitor*&
    trompeloeil_expect_death(
      trompeloeil::lifetime_monitor* monitor)
    const
    noexcept
    {
      auto lock = get_lock();
      trompeloeil_lifetime_monitor = monitor;
      return trompeloeil_lifetime_monitor.leak();
    }
  private:
    mutable null_on_move<trompeloeil::lifetime_monitor> trompeloeil_lifetime_monitor;
  };

  struct expectation {
    virtual ~expectation() = default;
    virtual bool is_satisfied() const noexcept = 0;
    virtual bool is_saturated() const noexcept = 0;
  };

  struct lifetime_monitor : public expectation
  {
    template <typename T>
    lifetime_monitor(
      ::trompeloeil::deathwatched<T> const &obj,
      char const* obj_name_,
      char const* invocation_name_,
      char const* call_name_,
      location loc_)
    noexcept
      : object_monitor(obj.trompeloeil_expect_death(this))
      , loc(loc_)
      , object_name(obj_name_)
      , invocation_name(invocation_name_)
      , call_name(call_name_)
    {
    }

    bool is_satisfied() const noexcept override
    {
      return died;
    }

    bool is_saturated() const noexcept override
    {
      return died;
    }

    lifetime_monitor(lifetime_monitor const&) = delete;

    ~lifetime_monitor() override
    {
      auto lock = get_lock();
      if (!died)
      {
        std::ostringstream os;
        os << "Object " << object_name << " is still alive";
        send_report<specialized>(severity::nonfatal, loc, os.str());
        object_monitor = nullptr; // prevent its death poking this cadaver
      }
    }

    void
    notify()
    noexcept
    {
      died = true;
      sequences->validate(severity::nonfatal, call_name, loc);

      sequences->increment_call();
      if (sequences->is_satisfied())
      {
        sequences->retire_predecessors();
      }
    }

    template <typename ... T>
    void
    set_sequence(
      T&& ... t)
    {
      using handler = sequence_handler<sizeof...(T)>;
      auto seq = detail::make_unique<handler>(*sequences,
                                              invocation_name,
                                              loc,
                                              std::forward<T>(t)...);
      sequences = std::move(seq);
    }
  private:
    atomic<bool>       died{false};
    lifetime_monitor *&object_monitor;
    location           loc;
    char const        *object_name;
    char const        *invocation_name;
    char const        *call_name;
    std::unique_ptr<sequence_handler_base>  sequences = detail::make_unique<sequence_handler<0>>();
  };

  template <typename T>
  deathwatched<T>::~deathwatched()
  {
    auto lock = get_lock();
    if (trompeloeil_lifetime_monitor)
    {
      trompeloeil_lifetime_monitor->notify();
      return;
    }
    std::ostringstream os;
    os << "Unexpected destruction of "
       << TROMPELOEIL_TYPE_ID_NAME(T) << "@" << this << '\n';
    send_report<specialized>(severity::nonfatal,
                             location{},
                             os.str());
  }

  template <typename T>
  struct return_of;

  template <typename R, typename ... A>
  struct return_of<R(A...)>
  {
    using type = R;
  };

  template <typename T>
  using return_of_t = typename return_of<T>::type;

  template <typename T>
  struct call_params_type;

  template <typename R, typename ... T>
  struct call_params_type<R(T...)>
  {
    using type = std::tuple<typename std::add_lvalue_reference<T>::type...>;
  };

  template <typename T>
  using call_params_type_t = typename call_params_type<T>::type;


  template <typename R>
  struct default_return_t
  {
    TROMPELOEIL_NORETURN static R value()
    {
      std::abort(); // must never be called
    }
  };

#if TROMPELOEIL_MSVC
#pragma warning(push)
#pragma warning(disable : 4702)
#endif
  template <typename R>
  inline
  R
  default_return()
  {
    return default_return_t<R>::value();
  }
#if TROMPELOEIL_MSVC
#pragma warning(pop)
#endif



  template <>
  inline
  void
  default_return<void>()
  {
    // Implicitly do nothing when returning from function returning void
  }

  template <typename Sig>
  struct call_matcher_base;

  template <typename Sig>
  struct call_matcher_list : public list<call_matcher_base<Sig>>
  {
    void decommission()
    {
      auto lock = get_lock();
      auto iter = this->begin();
      auto const e = this->end();
      while (iter != e)
      {
        auto &m = *iter;
        ++iter; // intrusive list, so must advance to next before destroying
        m.mock_destroyed();
        m.unlink();
      }
    }
  };

  template <typename Sig>
  struct call_matcher_base : public list_elem<call_matcher_base<Sig>>
  {
    call_matcher_base(
      location loc_,
      char const* name_)
    : loc{loc_}
    , name{name_}
    {
    }

    call_matcher_base(call_matcher_base&&) = delete;

    ~call_matcher_base() override = default;

    virtual
    void
    mock_destroyed() = 0;

    virtual
    bool
    matches(
      call_params_type_t<Sig> const&)
    const = 0;

    virtual
    unsigned
    sequence_cost()
    const
    noexcept = 0;

    virtual
    void
    run_actions(
      call_params_type_t<Sig> &,
      call_matcher_list<Sig> &saturated_list
    ) = 0;

    virtual
    std::ostream&
    report_signature(
      std::ostream&)
    const = 0;

    TROMPELOEIL_NORETURN
    virtual
    std::ostream&
    report_mismatch(
      std::ostream&,
      call_params_type_t<Sig> const &) = 0;

    virtual
    return_of_t<Sig>
    return_value(
      trace_agent&,
      call_params_type_t<Sig>& p) = 0;

    location loc;
    char const *name;
  };

  template <typename T, typename U>
  bool
  param_matches_impl(
    T const& t,
    U const& u,
    matcher const*)
  noexcept(noexcept(t.matches(u)))
  {
    return t.matches(u);
  }

  template <typename T,
            typename U,
            typename = detail::enable_if_t<is_equal_comparable<T, U>::value>>
  inline
  U&
  identity(
    U& t)
  noexcept
  {
    return t;
  }

  template <typename T,
            typename U,
            typename = detail::enable_if_t<!is_equal_comparable<T, U>::value>>
  inline
  T
  identity(
    const U& u)
  noexcept(noexcept(T(u)))
  {
    return u;
  }

  template <typename T, typename U>
  bool
  param_matches_impl(
    T const& t,
    U const& u,
    void const*)
  noexcept(noexcept(::trompeloeil::identity<U>(t) == u))
  {
    return ::trompeloeil::identity<U>(t) == u;
  }

  template <typename T, typename U>
  bool
  param_matches(
    T const& t,
    U const& u)
  noexcept(noexcept(param_matches_impl(t, u, &t)))
  {
    return ::trompeloeil::param_matches_impl(t, u, &t);
  }

  template <size_t ... I, typename T, typename U>
  bool
  match_parameters(
    detail::index_sequence<I...>,
    T const& t,
    U const& u)
    noexcept(noexcept(std::initializer_list<bool>{trompeloeil::param_matches(std::get<I>(t),std::get<I>(u))...}))
  {
    bool all_true = true;
    ::trompeloeil::ignore(t, u); // Kills unmotivated VS2015 warning in the empty case
    ::trompeloeil::ignore(std::initializer_list<bool>{all_true = all_true && ::trompeloeil::param_matches(std::get<I>(t), std::get<I>(u))...});
    return all_true;
  }

  template <typename ... T, typename ... U>
  bool
  match_parameters(
    std::tuple<T...> const& t,
    std::tuple<U...> const& u)
  noexcept(noexcept(match_parameters(detail::make_index_sequence<sizeof...(T)>{}, t, u)))
  {
    return ::trompeloeil::match_parameters(detail::make_index_sequence<sizeof...(T)>{}, t, u);
  }

  template <typename V, typename P>
  void print_mismatch(
    std::ostream& os,
    size_t num,
    V const& v,
    P const& p)
  {
    if (!::trompeloeil::param_matches(v, p))
    {
      auto prefix = ::trompeloeil::param_name_prefix(&v) + "_";
      os << "  Expected " << std::setw((num < 9) ? 2 : 1) << prefix << num+1;
      ::trompeloeil::print_expectation(os, v);
    }
  }

  template <typename ... V, typename ... P, size_t ... I>
  void print_mismatch(
    std::ostream& os,
    detail::index_sequence<I...>,
    std::tuple<V...> const& v,
    std::tuple<P...> const& p)
  {
    ::trompeloeil::ignore(os, v, p);  // Kills unmotivated VS2015 warning in the empty case
    ::trompeloeil::ignore(std::initializer_list<int>{(print_mismatch(os, I, std::get<I>(v), std::get<I>(p)),0)...});
  }

  template <typename ... V, typename ... P>
  void print_mismatch(
    std::ostream& os,
    std::tuple<V...> const& v,
    std::tuple<P...> const& p)
  {
    print_mismatch(os, detail::make_index_sequence<sizeof...(V)>{}, v, p);
  }

  template <typename T>
  void missed_value(
    std::ostream& os,
    int i,
    T const& t)
  {
    auto prefix = ::trompeloeil::param_name_prefix(&t) + "_";
    os << "  param " << std::setw((i < 9) ? 2 : 1) << prefix << i + 1
       << ::trompeloeil::param_compare_operator(&t);
    ::trompeloeil::print(os, t);
    os << '\n';
  }

  template <size_t ... I, typename ... T>
  void stream_params(
    std::ostream &os,
    detail::index_sequence<I...>,
    std::tuple<T...> const &t)
  {
    ::trompeloeil::ignore(os, t);  // Kills unmotivated VS2015 warning in the empty case
    ::trompeloeil::ignore(std::initializer_list<int>{(missed_value(os, I, std::get<I>(t)),0)...});
  }

  template <typename ... T>
  void
  stream_params(
    std::ostream &os,
    std::tuple<T...> const &t)
  {
    stream_params(os, detail::make_index_sequence<sizeof...(T)>{}, t);
  }

  template <typename ... T>
  std::string
  params_string(
    std::tuple<T...> const& t)
  {
    std::ostringstream os;
    stream_params(os, t);
    return os.str();
  }

  class trace_agent
  {
  public:
    trace_agent(
      location loc_,
      char const* name_,
      tracer* t_)
    : loc{loc_}
    , t{t_}
    {
      if (t)
      {
        os << name_ << " with.\n";
      }
    }

    trace_agent(trace_agent const&) = delete;

    trace_agent(trace_agent &&) = delete;

    ~trace_agent()
    {
      if (t)
      {
        t->trace(loc.file, loc.line, os.str());
      }
    }

    trace_agent&
    operator=(trace_agent const&) = delete;

    trace_agent&
    operator=(trace_agent &&) = delete;

    template <typename ... T>
    void
    trace_params(
      std::tuple<T...> const& params)
    {
      if (t)
      {
        stream_params(os, params);
      }
    }

    template <typename T>
    auto
    trace_return(
      T&& rv)
    -> T
    {
      if (t)
      {
        os << " -> ";
        print(os, rv);
        os << '\n';
      }
      return std::forward<T>(rv);
    }

    void
    trace_exception()
    {
      if (t)
      {
        try {
          throw;
        }
        catch (std::exception const& e)
        {
          os << "threw exception: what() = " << e.what() << '\n';
        }
        catch (...)
        {
          os << "threw unknown exception\n";
        }
      }
    }
  private:
    location loc;
    tracer* t;
    std::ostringstream os;
  };

  template <typename Sig>
  call_matcher_base <Sig> *
  find(
    call_matcher_list <Sig> &list,
    call_params_type_t <Sig> const &p)
  noexcept
  {
    call_matcher_base<Sig>* first_match = nullptr;
    unsigned lowest_cost = ~0U;
    for (auto& i : list)
    {
      if (i.matches(p))
      {
        unsigned cost = i.sequence_cost();
        if (cost == 0)
        {
          return &i;
        }
        if (!first_match || cost < lowest_cost)
        {
          first_match = &i;
          lowest_cost = cost;
        }
      }
    }
    return first_match;
  }

  template <typename Sig>
  TROMPELOEIL_NORETURN
  void
  report_mismatch(
    call_matcher_list <Sig> &matcher_list,
    call_matcher_list <Sig> &saturated_list,
    std::string const &name,
    call_params_type_t <Sig> const &p)
  {
    std::ostringstream os;
    os << "No match for call of " << name << " with.\n";
    stream_params(os, p);
    bool saturated_match = false;
    for (auto& m : saturated_list)
    {
      if (m.matches(p))
      {
        if (!saturated_match)
        {
          os << "\nMatches saturated call requirement\n";
          saturated_match = true;
        }
        os << "  ";
        m.report_signature(os) << '\n';
      }
    }
    if (!saturated_match)
    {
      for (auto& m : matcher_list)
      {
        os << "\nTried ";
        m.report_mismatch(os, p);
      }
    }
    send_report<specialized>(severity::fatal, location{}, os.str());
    std::abort(); // must never get here.
  }

  template <typename Sig>
  void
  report_match(
    call_matcher_list <Sig> &matcher_list)
  {
    if(! matcher_list.empty())
    {
        send_ok_report<specialized>((matcher_list.begin())->name);
    }
  }

  template <typename Sig>
  class return_handler
  {
  public:
    virtual
    ~return_handler() = default;

    virtual
    return_of_t<Sig>
    call(
      trace_agent&,
      call_params_type_t<Sig>& params) = 0;
  };


  template <typename Ret, typename F, typename P, typename = detail::enable_if_t<std::is_void<Ret>::value>>
  void
  trace_return(
    trace_agent const&,
    F& func,
    P& params)
  {
    func(params);
  }

  template <typename Ret, typename F, typename P, typename = detail::enable_if_t<!std::is_void<Ret>::value>>
  Ret
  trace_return(
    trace_agent& agent,
    F& func,
    P& params)
  {
    /* Work around VS 2017 15.7.x C4702 warning by
     * enclosing the operation in an otherwise
     * unnecessary try/catch block.
     */
    try
    {
      return agent.trace_return(func(params));
    }
    catch (...)
    {
      throw;
    }
  }

  template <typename Sig, typename T>
  class return_handler_t : public return_handler<Sig>
  {
  public:
    template <typename U>
    explicit
    return_handler_t(
      U&& u)
    : func(std::forward<U>(u))
    {}

    return_of_t<Sig>
    call(
      trace_agent& agent,
      call_params_type_t<Sig>& params)
    override
    {
      return trace_return<return_of_t<Sig>>(agent, func, params);
    }
  private:
    T func;
  };

  template <typename Sig>
  class condition_base : public list_elem<condition_base<Sig>>
  {
  public:
    explicit
    condition_base(
      char const *n)
    noexcept
      : id(n)
    {}

    ~condition_base() override = default;

    virtual
    bool
    check(
      call_params_type_t<Sig> const&)
    const = 0;

    virtual
    char const*
    name()
    const
    noexcept
    {
      return id;
    }
  private:
    char const *id;
  };

  template <typename Sig>
  using condition_list = list<condition_base<Sig>, delete_disposer>;

  template <typename Sig, typename Cond>
  struct condition : public condition_base<Sig>
  {
    condition(
      char const *str_,
      Cond c_)
      : condition_base<Sig>(str_)
      , c(c_) {}

    bool
    check(
      call_params_type_t<Sig> const & t)
    const
    override
    {
      return c(t);
    }

  private:
    Cond c;
  };

  template <typename Sig>
  struct side_effect_base : public list_elem<side_effect_base<Sig>>
  {
    ~side_effect_base() override = default;

    virtual
    void
    action(
      call_params_type_t<Sig> &)
    const = 0;
  };

  template <typename Sig>
  using side_effect_list = list<side_effect_base<Sig>, delete_disposer>;

  template <typename Sig, typename Action>
  struct side_effect : public side_effect_base<Sig>
  {
    template <typename A>
    explicit
    side_effect(
      A&& a_)
    : a(std::forward<A>(a_))
    {}

    void
    action(
      call_params_type_t<Sig> &t)
    const
    override
    {
      a(t);
    }
  private:
    Action a;
  };

  template <size_t L, size_t H = L>
  struct multiplicity { };

  template <typename R, typename Parent>
  struct return_injector : Parent
  {
    using return_type = R;
  };

  template <typename Parent>
  struct throw_injector : Parent
  {
    static bool const throws = true;
  };

  template <typename Parent>
  struct sideeffect_injector : Parent
  {
    static bool const side_effects = true;
  };

  template <typename Parent, size_t H>
  struct call_limit_injector : Parent
  {
    static bool   const call_limit_set = true;
    static size_t const upper_call_limit = H;
  };

  template <typename Parent>
  struct call_limit_injector<Parent, 0> : Parent
  {
    static bool   const call_limit_set = true;
    static size_t const upper_call_limit = 0;
  };

  template <typename Parent>
  struct sequence_injector : Parent
  {
    static bool const sequence_set = true;
  };

  template <typename Matcher, typename modifier_tag, typename Parent>
  struct call_modifier : public Parent
  {
    using typename Parent::signature;
    using typename Parent::return_type;
    using Parent::call_limit_set;
    using Parent::upper_call_limit;
    using Parent::sequence_set;
    using Parent::throws;
    using Parent::side_effects;

    call_modifier(
       Matcher* m)
    noexcept
      : matcher{m}
    {}

    template <typename D>
    call_modifier&&
    with(
      char const* str,
      D&& d)
    &&
    {
      matcher->add_condition(str, std::forward<D>(d));
      return std::move(*this);
    }

    template <typename A>
    call_modifier<Matcher, modifier_tag, sideeffect_injector<Parent>>
    sideeffect(
      A&& a)
    {
      constexpr bool forbidden = upper_call_limit == 0U;
      static_assert(!forbidden,
                    "SIDE_EFFECT for forbidden call does not make sense");
      matcher->add_side_effect(std::forward<A>(a));
      return {std::move(matcher)};
    }

    template <typename H>
    call_modifier<Matcher, modifier_tag, return_injector<return_of_t<signature>, Parent >>
    handle_return(
      H&& h)
    {
      using params_type = call_params_type_t<signature>&;
      using sigret = return_of_t<signature>;
      using ret = decltype(std::declval<H>()(std::declval<params_type>()));
      // don't know why MS VS 2015 RC doesn't like std::result_of

      constexpr bool is_illegal_type   = std::is_same<detail::decay_t<ret>, illegal_argument>::value;
      constexpr bool is_first_return   = std::is_same<return_type, void>::value;
      constexpr bool void_signature    = std::is_same<sigret, void>::value;
      constexpr bool is_pointer_sigret = std::is_pointer<sigret>::value;
      constexpr bool is_pointer_ret    = std::is_pointer<detail::decay_t<ret>>::value;
      constexpr bool ptr_const_mismatch =
        is_pointer_ret &&
        is_pointer_sigret &&
        !std::is_const<detail::remove_pointer_t<sigret>>{} &&
        std::is_const<detail::remove_pointer_t<detail::decay_t<ret>>>{};
      constexpr bool is_ref_sigret     = std::is_reference<sigret>::value;
      constexpr bool is_ref_ret        = std::is_reference<ret>::value;
      constexpr bool ref_const_mismatch=
        is_ref_ret &&
        is_ref_sigret &&
        !std::is_const<detail::remove_reference_t<sigret>>::value &&
        std::is_const<detail::remove_reference_t<ret>>::value;
      constexpr bool matching_ret_type = std::is_constructible<sigret, ret>::value;
      constexpr bool ref_value_mismatch = !is_ref_ret && is_ref_sigret;

      static_assert(matching_ret_type || !void_signature,
                    "RETURN does not make sense for void-function");
      static_assert(!is_illegal_type,
                    "RETURN illegal argument");
      static_assert(!ptr_const_mismatch,
                    "RETURN const* from function returning pointer to non-const");
      static_assert(!ref_value_mismatch || matching_ret_type,
                    "RETURN non-reference from function returning reference");
      static_assert(ref_value_mismatch || !ref_const_mismatch,
                    "RETURN const& from function returning non-const reference");

      static_assert(ptr_const_mismatch || ref_const_mismatch || is_illegal_type || matching_ret_type || void_signature,
                    "RETURN value is not convertible to the return type of the function");
      static_assert(is_first_return,
                    "Multiple RETURN does not make sense");
      static_assert(!throws || upper_call_limit == 0,
                    "THROW and RETURN does not make sense");
      static_assert(upper_call_limit > 0,
                    "RETURN for forbidden call does not make sense");

      constexpr bool valid = !is_illegal_type && matching_ret_type && is_first_return && !throws && upper_call_limit > 0;
      using tag = std::integral_constant<bool, valid>;
      matcher->set_return(tag{}, std::forward<H>(h));
      return {matcher};
    }

    call_modifier&&
    null_modifier()
    {
      return std::move(*this);
    }

  private:
    template <typename H>
    struct throw_handler_t
    {
      using R = decltype(default_return<return_of_t<signature>>());

      explicit
      throw_handler_t(H&& h_)
        : h(std::move(h_))
      {}

      template <typename T>
      R operator()(T& p)
      {
        /* Work around VS 2017 15.7.x C4702 warning by
         * enclosing the operation in an otherwise
         * unnecessary try/catch block.
         */
        try
        {
          h(p);
          abort();
        }
        catch (...)
        {
          throw;
        }
        return default_return<R>(); // unreachable code
      }

    private:
      H h;
    };

  public:
    template <typename H>
    call_modifier<Matcher, modifier_tag, throw_injector<Parent>>
    handle_throw(
      H&& h)
    {
      static_assert(!throws,
                    "Multiple THROW does not make sense");
      constexpr bool has_return = !std::is_same<return_type, void>::value;
      static_assert(!has_return,
                    "THROW and RETURN does not make sense");

      constexpr bool forbidden = upper_call_limit == 0U;

      static_assert(!forbidden,
                    "THROW for forbidden call does not make sense");

      constexpr bool valid = !throws && !has_return;
      using tag = std::integral_constant<bool, valid>;
      auto handler = throw_handler_t<H>(std::forward<H>(h));
      matcher->set_return(tag{}, std::move(handler));
      return {matcher};
    }

    template <size_t L,
              size_t H,
              bool               times_set = call_limit_set>
    call_modifier<Matcher, modifier_tag, call_limit_injector<Parent, H>>
    times(
      multiplicity<L, H>)
    {
      static_assert(!times_set,
                    "Only one TIMES call limit is allowed, but it can express an interval");

      static_assert(H >= L,
                    "In TIMES the first value must not exceed the second");

      static_assert(H > 0 || !throws,
                    "THROW and TIMES(0) does not make sense");

      static_assert(H > 0 || std::is_same<return_type, void>::value,
                    "RETURN and TIMES(0) does not make sense");

      static_assert(H > 0 || !side_effects,
                    "SIDE_EFFECT and TIMES(0) does not make sense");

      static_assert(H > 0 || !sequence_set,
                    "IN_SEQUENCE and TIMES(0) does not make sense");

      matcher->sequences->set_limits(L, H);
      return {matcher};
    }

    template <typename ... T,
              bool b = sequence_set>
    call_modifier<Matcher, modifier_tag, sequence_injector<Parent>>
    in_sequence(
      T&& ... t)
    {
      static_assert(!b,
                    "Multiple IN_SEQUENCE does not make sense."
                    " You can list several sequence objects at once");

      static_assert(upper_call_limit > 0,
                    "IN_SEQUENCE for forbidden call does not make sense");

      matcher->set_sequence(std::forward<T>(t)...);
      return {matcher};
    }
    Matcher* matcher;
  };

  inline
  void
  report_unfulfilled(
    const char* reason,
    char const        *name,
    std::string const &values,
    size_t min_calls,
    size_t call_count,
    location           loc)
  {
    std::ostringstream os;
    os << reason
       << ":\nExpected " << name << " to be called ";
    if (min_calls == 1)
      os << "once";
    else
      os << min_calls << " times";
    os << ", actually ";
    switch (call_count)
    {
    case 0:
      os << "never called\n"; break;
    case 1:
      os << "called once\n"; break;
    default:
      os << "called " << call_count << " times\n";
    }
    os << values;
    send_report<specialized>(severity::nonfatal, loc, os.str());
  }

  inline
  void
  report_forbidden_call(
    char const *name,
    location loc,
    std::string const& values)
  {
    std::ostringstream os;
    os << "Match of forbidden call of " << name
       << " at " << loc << '\n' << values;
    send_report<specialized>(severity::fatal, loc, os.str());
  }

  template <typename Sig>
  struct matcher_info
  {
    using signature = Sig;
    using return_type = void;
    static size_t const upper_call_limit = 1;
    static bool const throws = false;
    static bool const call_limit_set = false;
    static bool const sequence_set = false;
    static bool const side_effects = false;
  };


  template <typename Sig, typename Value>
  struct call_matcher : public call_matcher_base<Sig>, expectation
  {
    using call_matcher_base<Sig>::name;
    using call_matcher_base<Sig>::loc;

    template <typename ... U>
    call_matcher(
      char const *file,
      unsigned long line,
      char const *call_string,
      U &&... u)
    : call_matcher_base<Sig>(location{file, line}, call_string)
    , val(std::forward<U>(u)...)
    {}

    call_matcher(call_matcher &&r) = delete;

    ~call_matcher() override
    {
      auto lock = get_lock();
      if (is_unfulfilled())
      {
        report_missed("Unfulfilled expectation");
      }
      this->unlink();
    }

    bool
    is_satisfied()
      const
      noexcept
      override
    {
      auto lock = get_lock();
      return sequences->is_satisfied();
    }

    bool
    is_saturated()
      const
      noexcept
      override
    {
      auto lock = get_lock();
      return sequences->is_saturated();
    }
    bool
    is_unfulfilled()
    const
    noexcept
    {
      return !reported && this->is_linked() && !sequences->is_satisfied();
    }

    void
    mock_destroyed()
    override
    {
      if (is_unfulfilled())
      {
        report_missed("Pending expectation on destroyed mock object");
      }
    }

    call_matcher*
    hook_last(
      call_matcher_list<Sig> &list)
    noexcept
    {
      list.push_front(this);
      return this;
    }

    bool
    matches(
      call_params_type_t<Sig> const& params)
    const
    override
    {
      return match_parameters(val, params) && match_conditions(params);
    }

    bool
    match_conditions(
      call_params_type_t<Sig> const & params)
    const
    {
      // std::all_of() is almost always preferable. The only reason
      // for using a hand rolled loop is because it cuts compilation
      // times quite noticeably (almost 10% with g++5.1)
      for (auto& c : conditions)
      {
        if (!c.check(params)) return false;
      }
      return true;
    }

    unsigned
    sequence_cost()
      const
      noexcept
      override
    {
      return sequences->order();
    }

    return_of_t<Sig>
    return_value(
      trace_agent& agent,
      call_params_type_t<Sig>& params)
    override
    {
      if (!return_handler_obj) return default_return<return_of_t<Sig>>();
      return return_handler_obj->call(agent, params);
    }

    void
    run_actions(
      call_params_type_t<Sig>& params,
      call_matcher_list<Sig> &saturated_list)
    override
    {
      if (sequences->is_forbidden())
      {
        reported = true;
        report_forbidden_call(name, loc, params_string(params));
      }
      auto lock = get_lock();
      {
        if (!sequences->can_be_called())
        {
          sequences->validate(severity::fatal, name, loc);
        }
        sequences->increment_call();
        if (sequences->is_satisfied())
        {
          sequences->retire_predecessors();
        }
        if (sequences->is_saturated())
        {
          sequences->retire();
          this->unlink();
          saturated_list.push_back(this);
        }
      }
      for (auto& a : actions) a.action(params);
    }

    std::ostream&
    report_signature(
      std::ostream& os)
    const override
    {
      return os << name << " at " << loc;
    }

    std::ostream&
    report_mismatch(
      std::ostream& os,
      call_params_type_t<Sig> const & params)
    override
    {
      reported = true;
      report_signature(os);
      if (match_parameters(val, params))
      {
        for (auto& cond : conditions)
        {
          if (!cond.check(params))
          {
            os << "\n  Failed WITH(" << cond.name() << ')';
          }
        }
      }
      else
      {
        os << '\n';
        ::trompeloeil::print_mismatch(os, val, params);
      }
      return os;
    }

    void
    report_missed(
      char const *reason)
    noexcept
    {
      reported = true;
      report_unfulfilled(
        reason,
        name,
        params_string(val),
        sequences->get_min_calls(),
        sequences->get_calls(),
        loc);
    }

    template <typename C>
    void
    add_condition(
      char const *str,
      C&& c)
    {
      auto cond = new condition<Sig, C>(str, std::forward<C>(c));
      conditions.push_back(cond);
    }

    template <typename S>
    void
    add_side_effect(
      S&& s)
    {
      auto effect = new side_effect<Sig, S>(std::forward<S>(s));
      actions.push_back(effect);
    }

    template <typename ... T>
    void
    set_sequence(
      T&& ... t)
    {
      using handler = sequence_handler<sizeof...(T)>;
      auto seq = detail::make_unique<handler>(*sequences,
                                              name,
                                              loc,
                                              std::forward<T>(t)...);
      sequences = std::move(seq);
    }

    template <typename T>
    inline
    void
    set_return(
      std::true_type,
      T&& h)
    {
      using basic_t = typename std::remove_reference<T>::type;
      using handler = return_handler_t<Sig, basic_t>;
      return_handler_obj.reset(new handler(std::forward<T>(h)));
    }

    template <typename T>            // Never called. Used to limit errmsg
    static                           // with RETURN of wrong type and after:
    void                             //   FORBIDDEN_CALL
    set_return(std::false_type, T&&t)//   RETURN
      noexcept;                      //   THROW

    condition_list<Sig>                    conditions;
    side_effect_list<Sig>                  actions;
    std::unique_ptr<return_handler<Sig>>   return_handler_obj;
    std::unique_ptr<sequence_handler_base> sequences = detail::make_unique<sequence_handler<0>>();
    Value                                  val;
    bool                                   reported = false;
  };

  /* Clang (all versions) does not like computing the return type R
   * before determining if the function overload is the best match.
   */
  template <
    int N,
    typename T,
    typename = detail::enable_if_t<N <= std::tuple_size<T>::value>,
    typename R = decltype(std::get<N-1>(std::declval<T>()))
  >
  constexpr
  TROMPELOEIL_DECLTYPE_AUTO
  arg(
    T* t,
    std::true_type)
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return std::get<N-1>(*t);
  }

  template <int>
  constexpr
  illegal_argument
  arg(
    void const*,
    std::false_type)
  noexcept
  {
    return {};
  }

  template <
    int N,
    typename T,
    typename R = decltype(arg<N>(std::declval<T*>(),
                                 std::integral_constant<bool, (N <= std::tuple_size<T>::value)>{}))
  >
  TROMPELOEIL_DECLTYPE_AUTO
  mkarg(
    T& t)
  noexcept
  TROMPELOEIL_TRAILING_RETURN_TYPE(R)
  {
    return arg<N>(&t, std::integral_constant<bool, (N <= std::tuple_size<T>::value)>{});
  }

  template <typename Mock>
  struct call_validator_t
  {
    template <typename M, typename Tag, typename Info>
    auto
    make_expectation(
      std::true_type,
      call_modifier<M, Tag, Info> const& m)
    const
    noexcept
    TROMPELOEIL_TRAILING_RETURN_TYPE(std::unique_ptr<expectation>)
    {
      auto lock = get_lock();
      m.matcher->hook_last(obj.trompeloeil_matcher_list(static_cast<Tag*>(nullptr)));

      return std::unique_ptr<expectation>(m.matcher);
    }

    template <typename T>
    static                                           // Never called. Used to
    std::unique_ptr<expectation>                     // limit errmsg when RETURN
    make_expectation(std::false_type, T&&) noexcept; // is missing in non-void
                                                     // function

    template <typename M, typename Tag, typename Info>
    inline
    auto
    operator+(
      call_modifier<M, Tag, Info>&& t)
    const
    TROMPELOEIL_TRAILING_RETURN_TYPE(std::unique_ptr<expectation>)
    {
      using call = call_modifier<M, Tag, Info>;
      using sigret = return_of_t<typename call::signature>;
      using ret = typename call::return_type;
      constexpr bool retmatch = std::is_same<ret, sigret>::value;
      constexpr bool forbidden = call::upper_call_limit == 0;
      constexpr bool valid_return_type = call::throws || retmatch || forbidden;
      static_assert(valid_return_type, "RETURN missing for non-void function");
      auto tag = std::integral_constant<bool, valid_return_type>{};
      return make_expectation(tag, std::move(t));
    }
    Mock& obj;
  };

  template <typename T,
            typename = detail::enable_if_t<std::is_lvalue_reference<T&&>::value>>
  inline
  T&&
  decay_return_type(
    T&& t)
  {
    return std::forward<T>(t);
  }

  template <typename T,
            typename = detail::enable_if_t<std::is_rvalue_reference<T&&>::value>>
  inline
  T
  decay_return_type(
    T&& t)
  {
    return std::forward<T>(t);
  }

  template <typename T, size_t N>
  inline
  T*
  decay_return_type(
    T (&t)[N])
  {
    return t;
  }

  template <bool sequence_set>
  struct lifetime_monitor_modifier : std::unique_ptr<lifetime_monitor>
  {
    explicit
    lifetime_monitor_modifier(
      std::unique_ptr<lifetime_monitor>&& p)
    noexcept
    : unique_ptr(std::move(p))
    {}

    template <typename ... T, bool b = sequence_set>
    auto
    in_sequence(T&& ... t)
    -> lifetime_monitor_modifier<true>
    {
      static_assert(!b,
                    "Multiple IN_SEQUENCE does not make sense."
                      " You can list several sequence objects at once");
      std::unique_ptr<lifetime_monitor>& m = *this;
      m->set_sequence(std::forward<T>(t)...);
      return lifetime_monitor_modifier<true>{std::move(m)};
    }
  };

  struct lifetime_monitor_releaser
  {
    template <bool b>
    std::unique_ptr<trompeloeil::lifetime_monitor>
    operator+(
      lifetime_monitor_modifier<b>&& m)
    const
    {
      return std::move(m);
    }
  };

  template <bool movable, typename Sig>
  struct expectations
  {
    expectations() = default;
    expectations(expectations&&) noexcept = default;
    ~expectations() {
      active.decommission();
      saturated.decommission();
    }
    call_matcher_list<Sig> active{};
    call_matcher_list<Sig> saturated{};
  };

  template <typename Sig>
  struct expectations<false, Sig>
  {
    expectations() = default;
    expectations(expectations&&)
    noexcept
    {
      static_assert(std::is_same<Sig,void>::value,
        "By default, mock objects are not movable. "
        "To make a mock object movable, see: "
        "https://github.com/rollbear/trompeloeil/blob/master/docs/reference.md#movable_mock");
    }
    ~expectations() {
      active.decommission();
      saturated.decommission();
    }
    call_matcher_list<Sig> active{};
    call_matcher_list<Sig> saturated{};
  };

  template <typename Sig, typename ... P>
  return_of_t<Sig> mock_func(std::false_type, P&& ...);


  template <bool movable, typename Sig, typename ... P>
  return_of_t<Sig>
  mock_func(std::true_type,
            expectations<movable, Sig>& e,
            char const *func_name,
            char const *sig_name,
            P&& ... p)
  {
    auto lock = get_lock();

    call_params_type_t<void(P...)> param_value(std::forward<P>(p)...);

    auto i = find(e.active, param_value);
    if (!i)
    {
      report_mismatch(e.active,
                      e.saturated,
                      func_name + std::string(" with signature ") + sig_name,
                      param_value);
    }
    else{
        report_match(e.active);
    }
    trace_agent ta{i->loc, i->name, tracer_obj()};
    try
    {
      ta.trace_params(param_value);
      i->run_actions(param_value, e.saturated);
      return i->return_value(ta, param_value);
    }
    catch (...)
    {
      ta.trace_exception();
      throw;
    }
  }

  template <typename ... U>
  struct param_helper {
    using type = decltype(detail::make_tuple(std::declval<U>()...));
  };

  template <typename ... U>
  using param_t = typename param_helper<U...>::type;

  template <typename sig, typename tag, typename... U>
  using modifier_t = call_modifier<call_matcher<sig, param_t<U...>>,
                                   tag,
                                   matcher_info<sig>>;

  template <typename M,
            typename = detail::enable_if_t<::trompeloeil::is_matcher<M>::value>>
  inline
  ::trompeloeil::ptr_deref<detail::decay_t<M>>
  operator*(
    M&& m)
  {
    return ::trompeloeil::ptr_deref<detail::decay_t<M>>{std::forward<M>(m)};
  }

  template <typename M,
            typename = detail::enable_if_t<::trompeloeil::is_matcher<M>::value>>
  inline
  ::trompeloeil::neg_matcher<detail::decay_t<M>>
  operator!(
    M&& m)
  {
    return ::trompeloeil::neg_matcher<detail::decay_t<M>>{std::forward<M>(m)};
  }

  /*
   * Convert the signature S of a mock function to the signature of
   * a member function of class T that takes the same parameters P
   * but returns R.
   *
   * The member function has the same constness as the mock function.
   */
  template <typename T, typename R, typename S>
  struct signature_to_member_function;

  template <typename T, typename R, typename R_of_S, typename... P>
  struct signature_to_member_function<T, R, R_of_S(P...)>
  {
    using type = detail::conditional_t<
      std::is_const<T>::value,
      R (T::*)(P...) const,
      R (T::*)(P...)>;
  };

  template <typename T>
  struct mock_interface : public T
  {
    using trompeloeil_interface_name = T;
    using T::T;
 };

#if defined(TROMPELOEIL_USER_DEFINED_COMPILE_TIME_REPORTER)
 extern template struct reporter<specialized>;
#endif // TROMPELOEIL_USER_DEFINED_COMPILE_TIME_REPORTER
}

#define TROMPELOEIL_LINE_ID(name)                                        \
  TROMPELOEIL_CONCAT(trompeloeil_l_ ## name ## _, __LINE__)

#define TROMPELOEIL_COUNT_ID(name)                                       \
  TROMPELOEIL_CONCAT(trompeloeil_c_ ## name ## _, __COUNTER__)

#if TROMPELOEIL_MSVC
#define TROMPELOEIL_MAKE_MOCK0(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,0, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK1(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,1, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK2(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,2, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK3(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,3, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK4(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,4, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK5(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,5, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK6(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,6, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK7(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,7, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK8(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,8, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK9(name, sig, ...)                           \
  TROMPELOEIL_MAKE_MOCK_(name,,9, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK10(name, sig, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,,10, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK11(name, sig, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,,11, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK12(name, sig, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,,12, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK13(name, sig, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,,13, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK14(name, sig, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,,14, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK15(name, sig, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,,15, sig, __VA_ARGS__,,)

#define TROMPELOEIL_MAKE_CONST_MOCK0(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,0, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK1(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,1, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK2(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,2, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK3(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,3, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK4(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,4, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK5(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,5, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK6(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,6, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK7(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,7, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK8(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,8, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK9(name, sig, ...)                     \
  TROMPELOEIL_MAKE_MOCK_(name,const,9, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK10(name, sig, ...)                    \
  TROMPELOEIL_MAKE_MOCK_(name,const,10, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK11(name, sig, ...)                    \
  TROMPELOEIL_MAKE_MOCK_(name,const,11, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK12(name, sig, ...)                    \
  TROMPELOEIL_MAKE_MOCK_(name,const,12, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK13(name, sig, ...)                    \
  TROMPELOEIL_MAKE_MOCK_(name,const,13, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK14(name, sig, ...)                    \
  TROMPELOEIL_MAKE_MOCK_(name,const,14, sig, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK15(name, sig, ...)                    \
  TROMPELOEIL_MAKE_MOCK_(name,const,15, sig, __VA_ARGS__,,)


#else
// sane standards compliant preprocessor

#define TROMPELOEIL_MAKE_MOCK0(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,0, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK1(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,1, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK2(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,2, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK3(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,3, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK4(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,4, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK5(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,5, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK6(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,6, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK7(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,7, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK8(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,8, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK9(name, ...)                                \
  TROMPELOEIL_MAKE_MOCK_(name,,9, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK10(name, ...)                               \
  TROMPELOEIL_MAKE_MOCK_(name,,10, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK11(name, ...)                               \
  TROMPELOEIL_MAKE_MOCK_(name,,11, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK12(name, ...)                               \
  TROMPELOEIL_MAKE_MOCK_(name,,12, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK13(name, ...)                               \
  TROMPELOEIL_MAKE_MOCK_(name,,13, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK14(name, ...)                               \
  TROMPELOEIL_MAKE_MOCK_(name,,14,__VA_ARGS__,,)
#define TROMPELOEIL_MAKE_MOCK15(name, ...)                               \
  TROMPELOEIL_MAKE_MOCK_(name,,15, __VA_ARGS__,,)

#define TROMPELOEIL_MAKE_CONST_MOCK0(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,0, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK1(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,1, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK2(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,2, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK3(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,3, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK4(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,4, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK5(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,5, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK6(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,6, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK7(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,7, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK8(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,8, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK9(name, ...)                          \
  TROMPELOEIL_MAKE_MOCK_(name,const,9, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK10(name, ...)                         \
  TROMPELOEIL_MAKE_MOCK_(name,const,10, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK11(name, ...)                         \
  TROMPELOEIL_MAKE_MOCK_(name,const,11, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK12(name, ...)                         \
  TROMPELOEIL_MAKE_MOCK_(name,const,12, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK13(name, ...)                         \
  TROMPELOEIL_MAKE_MOCK_(name,const,13, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK14(name, ...)                         \
  TROMPELOEIL_MAKE_MOCK_(name,const,14, __VA_ARGS__,,)
#define TROMPELOEIL_MAKE_CONST_MOCK15(name, ...)                         \
  TROMPELOEIL_MAKE_MOCK_(name,const,15, __VA_ARGS__,,)

#endif

#define TROMPELOEIL_IMPLEMENT_MOCK0(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(0, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK1(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(1, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK2(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(2, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK3(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(3, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK4(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(4, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK5(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(5, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK6(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(6, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK7(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(7, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK8(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(8, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK9(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(9, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK10(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(10, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK11(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(11, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK12(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(12, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK13(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(13, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK14(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(14, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_MOCK15(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_MOCK_(15, __VA_ARGS__,override))

#define TROMPELOEIL_IMPLEMENT_CONST_MOCK0(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(0, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK1(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(1, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK2(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(2, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK3(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(3, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK4(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(4, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK5(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(5, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK6(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(6, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK7(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(7, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK8(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(8, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK9(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(9, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK10(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(10, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK11(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(11, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK12(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(12, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK13(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(13, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK14(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(14, __VA_ARGS__,override))
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK15(...) \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_IMPLEMENT_CONST_MOCK_(15, __VA_ARGS__,override))


#define TROMPELOEIL_IMPLEMENT_MOCK_(num, name, ...) \
  TROMPELOEIL_MAKE_MOCK_(name,\
                         ,\
                         num,\
                         decltype(::trompeloeil::nonconst_member_signature(&trompeloeil_interface_name::name))::type,\
                         TROMPELOEIL_SEPARATE(__VA_ARGS__),)
#define TROMPELOEIL_IMPLEMENT_CONST_MOCK_(num, name, ...) \
  TROMPELOEIL_MAKE_MOCK_(name,\
                         const,\
                         num,\
                         decltype(::trompeloeil::const_member_signature(&trompeloeil_interface_name::name))::type,\
                         TROMPELOEIL_SEPARATE(__VA_ARGS__),)

#define TROMPELOEIL_MAKE_MOCK_(name, constness, num, sig, spec, ...)           \
  private:                                                                     \
  using TROMPELOEIL_LINE_ID(cardinality_match) =                               \
    std::integral_constant<bool, num ==                                        \
      ::trompeloeil::param_list<TROMPELOEIL_REMOVE_PAREN(sig)>::size>;         \
  static_assert(TROMPELOEIL_LINE_ID(cardinality_match)::value,                 \
                "Function signature does not have " #num " parameters");       \
  using TROMPELOEIL_LINE_ID(matcher_list_t) =                                  \
  ::trompeloeil::call_matcher_list<TROMPELOEIL_REMOVE_PAREN(sig)>;             \
  using TROMPELOEIL_LINE_ID(expectation_list_t) =                              \
    ::trompeloeil::expectations<trompeloeil_movable_mock,                      \
                                TROMPELOEIL_REMOVE_PAREN(sig)>;                \
                                                                               \
  struct TROMPELOEIL_LINE_ID(tag_type_trompeloeil)                             \
  {                                                                            \
    const char* trompeloeil_expectation_file;                                  \
    unsigned long trompeloeil_expectation_line;                                \
    const char *trompeloeil_expectation_string;                                \
                                                                               \
    /* Work around parsing bug in VS 2015 when a "complex" */                  \
    /* decltype() appears in a trailing return type. */                        \
    /* Further, work around C2066 defect in VS 2017 15.7.1. */                 \
    using trompeloeil_sig_t = typename                                         \
    ::trompeloeil::identity_type<TROMPELOEIL_REMOVE_PAREN(sig)>::type;         \
                                                                               \
    using trompeloeil_call_params_type_t =                                     \
      ::trompeloeil::call_params_type_t<TROMPELOEIL_REMOVE_PAREN(sig)>;        \
                                                                               \
    using trompeloeil_return_of_t =                                            \
      ::trompeloeil::return_of_t<TROMPELOEIL_REMOVE_PAREN(sig)>;               \
                                                                               \
    template <typename ... trompeloeil_param_type>                             \
    auto name(                                                                 \
      trompeloeil_param_type&& ... trompeloeil_param)                          \
      -> ::trompeloeil::modifier_t<trompeloeil_sig_t,                          \
                                   TROMPELOEIL_LINE_ID(tag_type_trompeloeil),  \
                                   trompeloeil_param_type...>                  \
    {                                                                          \
      using matcher = ::trompeloeil::call_matcher<                             \
                          TROMPELOEIL_REMOVE_PAREN(sig),                       \
                          ::trompeloeil::param_t<trompeloeil_param_type...>>;  \
      return {                                                                 \
          new matcher {                                                        \
                trompeloeil_expectation_file,                                  \
                trompeloeil_expectation_line,                                  \
                trompeloeil_expectation_string,                                \
                std::forward<trompeloeil_param_type>(trompeloeil_param)...     \
              }                                                                \
      };                                                                       \
    }                                                                          \
  };                                                                           \
                                                                               \
  public:                                                                      \
  TROMPELOEIL_LINE_ID(matcher_list_t)&                                         \
  trompeloeil_matcher_list(                                                    \
    TROMPELOEIL_LINE_ID(tag_type_trompeloeil)*)                                \
  constness                                                                    \
  noexcept                                                                     \
  {                                                                            \
    return TROMPELOEIL_LINE_ID(expectations).active;                           \
  }                                                                            \
                                                                               \
  ::trompeloeil::return_of_t<TROMPELOEIL_REMOVE_PAREN(sig)>                    \
  name(TROMPELOEIL_PARAM_LIST(num, sig))                                       \
  constness                                                                    \
  spec                                                                         \
  {                                                                            \
    return ::trompeloeil::mock_func<trompeloeil_movable_mock, TROMPELOEIL_REMOVE_PAREN(sig)>( \
                                    TROMPELOEIL_LINE_ID(cardinality_match){},  \
                                    TROMPELOEIL_LINE_ID(expectations),         \
                                    #name,                                     \
                                    #sig                                       \
                                    TROMPELOEIL_PARAMS(num));                  \
  }                                                                            \
                                                                               \
  TROMPELOEIL_NOT_IMPLEMENTED(                                                 \
  auto                                                                         \
  trompeloeil_self_ ## name(TROMPELOEIL_PARAM_LIST(num, sig)) constness        \
  -> decltype(*this));                                                         \
                                                                               \
  TROMPELOEIL_NOT_IMPLEMENTED(TROMPELOEIL_LINE_ID(tag_type_trompeloeil)        \
  trompeloeil_tag_ ## name(TROMPELOEIL_PARAM_LIST(num, sig)) constness);       \
                                                                               \
  private:                                                                     \
  mutable                                                                      \
  TROMPELOEIL_LINE_ID(expectation_list_t) TROMPELOEIL_LINE_ID(expectations){}; \
                                                                               \
  public:                                                                      \
  /* An unused alias declaration to make trailing semicolon acceptable. */     \
  using TROMPELOEIL_LINE_ID(unused_alias) = void


#define TROMPELOEIL_LPAREN (

#define TROMPELOEIL_MORE_THAN_TWO_ARGS(...)                                    \
  TROMPELOEIL_IDENTITY(                                                        \
    TROMPELOEIL_ARG16(__VA_ARGS__,                                             \
                      T, T, T, T, T, T, T, T, T, T, T, T, T, F, F, F))


#define TROMPELOEIL_REQUIRE_CALL_V(...)                                        \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_REQUIRE_CALL_IMPL TROMPELOEIL_LPAREN        \
      TROMPELOEIL_MORE_THAN_TWO_ARGS(__VA_ARGS__), __VA_ARGS__))

// Dispatch to _F (0, 1, or 2 arguments) or _T (> 2 arguments) macro
#define TROMPELOEIL_REQUIRE_CALL_IMPL(N, ...)                                  \
    TROMPELOEIL_IDENTITY(                                                      \
      TROMPELOEIL_REQUIRE_CALL_ ## N TROMPELOEIL_LPAREN __VA_ARGS__))

// Accept only two arguments
#define TROMPELOEIL_REQUIRE_CALL_F(obj, func)                                  \
  auto TROMPELOEIL_COUNT_ID(call_obj) =                                        \
    TROMPELOEIL_REQUIRE_CALL_V_LAMBDA(obj, func, #obj, #func, .null_modifier())

// Accept three or more arguments.
#define TROMPELOEIL_REQUIRE_CALL_T(obj, func, ...)                             \
  auto TROMPELOEIL_COUNT_ID(call_obj) =                                        \
    TROMPELOEIL_REQUIRE_CALL_V_LAMBDA(obj, func, #obj, #func, __VA_ARGS__)


#define TROMPELOEIL_REQUIRE_CALL_V_LAMBDA(obj, func, obj_s, func_s, ...)       \
  [&]                                                                          \
  {                                                                            \
    using trompeloeil_s_t = decltype((obj)                                     \
                              .TROMPELOEIL_CONCAT(trompeloeil_self_, func));   \
    using trompeloeil_e_t = decltype((obj)                                     \
                              .TROMPELOEIL_CONCAT(trompeloeil_tag_,func));     \
                                                                               \
    return TROMPELOEIL_REQUIRE_CALL_LAMBDA_OBJ(obj, func, obj_s, func_s)       \
      __VA_ARGS__                                                              \
      ;                                                                        \
  }()


#define TROMPELOEIL_REQUIRE_CALL_LAMBDA_OBJ(obj, func, obj_s, func_s)          \
  ::trompeloeil::call_validator_t<trompeloeil_s_t>{(obj)} +                    \
      ::trompeloeil::detail::conditional_t<false,                              \
                                           decltype((obj).func),               \
                                           trompeloeil_e_t>                    \
    {__FILE__, static_cast<unsigned long>(__LINE__), obj_s "." func_s}.func


#define TROMPELOEIL_NAMED_REQUIRE_CALL_V(...)                                  \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_NAMED_REQUIRE_CALL_IMPL TROMPELOEIL_LPAREN  \
    TROMPELOEIL_MORE_THAN_TWO_ARGS(__VA_ARGS__), __VA_ARGS__))

// Dispatch to _F (0, 1, or 2 arguments) or _T (> 2 arguments) macro
#define TROMPELOEIL_NAMED_REQUIRE_CALL_IMPL(N, ...)                            \
  TROMPELOEIL_IDENTITY(                                                        \
    TROMPELOEIL_NAMED_REQUIRE_CALL_ ## N TROMPELOEIL_LPAREN __VA_ARGS__))

// Accept only two arguments
#define TROMPELOEIL_NAMED_REQUIRE_CALL_F(obj, func)                            \
  TROMPELOEIL_REQUIRE_CALL_V_LAMBDA(obj, func, #obj, #func, .null_modifier())

// Accept three or more arguments.
#define TROMPELOEIL_NAMED_REQUIRE_CALL_T(obj, func, ...)                       \
  TROMPELOEIL_REQUIRE_CALL_V_LAMBDA(obj, func, #obj, #func, __VA_ARGS__)


#define TROMPELOEIL_ALLOW_CALL_V(...)                                          \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_ALLOW_CALL_IMPL TROMPELOEIL_LPAREN          \
    TROMPELOEIL_MORE_THAN_TWO_ARGS(__VA_ARGS__), __VA_ARGS__))

// Dispatch to _F (0, 1, or 2 arguments) or _T (> 2 arguments) macro
#define TROMPELOEIL_ALLOW_CALL_IMPL(N, ...)                                    \
  TROMPELOEIL_IDENTITY(                                                        \
    TROMPELOEIL_ALLOW_CALL_ ## N TROMPELOEIL_LPAREN __VA_ARGS__))

// Accept only two arguments
#define TROMPELOEIL_ALLOW_CALL_F(obj, func)                                    \
  TROMPELOEIL_REQUIRE_CALL_T(obj, func, .TROMPELOEIL_INFINITY_TIMES())

// Accept three or more arguments.
#define TROMPELOEIL_ALLOW_CALL_T(obj, func, ...)                               \
  TROMPELOEIL_REQUIRE_CALL_T(obj,                                              \
                             func,                                             \
                             .TROMPELOEIL_INFINITY_TIMES() __VA_ARGS__)


#define TROMPELOEIL_NAMED_ALLOW_CALL_V(...)                                    \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_NAMED_ALLOW_CALL_IMPL TROMPELOEIL_LPAREN    \
    TROMPELOEIL_MORE_THAN_TWO_ARGS(__VA_ARGS__), __VA_ARGS__))

// Dispatch to _F (0, 1, or 2 arguments) or _T (> 2 arguments) macro
#define TROMPELOEIL_NAMED_ALLOW_CALL_IMPL(N, ...)                              \
  TROMPELOEIL_IDENTITY(                                                        \
    TROMPELOEIL_NAMED_ALLOW_CALL_ ## N TROMPELOEIL_LPAREN __VA_ARGS__))

// Accept only two arguments
#define TROMPELOEIL_NAMED_ALLOW_CALL_F(obj, func)                              \
  TROMPELOEIL_NAMED_REQUIRE_CALL_T(obj, func, .TROMPELOEIL_INFINITY_TIMES())

// Accept three or more arguments.
#define TROMPELOEIL_NAMED_ALLOW_CALL_T(obj, func, ...)                         \
  TROMPELOEIL_NAMED_REQUIRE_CALL_T(obj,                                        \
                                   func,                                       \
                                   .TROMPELOEIL_INFINITY_TIMES()               \
                                   __VA_ARGS__)


#define TROMPELOEIL_FORBID_CALL_V(...)                                         \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_FORBID_CALL_IMPL TROMPELOEIL_LPAREN         \
    TROMPELOEIL_MORE_THAN_TWO_ARGS(__VA_ARGS__), __VA_ARGS__))

// Dispatch to _F (0, 1, or 2 arguments) or _T (> 2 arguments) macro
#define TROMPELOEIL_FORBID_CALL_IMPL(N, ...)                                   \
  TROMPELOEIL_IDENTITY(                                                        \
    TROMPELOEIL_FORBID_CALL_ ## N TROMPELOEIL_LPAREN __VA_ARGS__))

// Accept only two arguments
#define TROMPELOEIL_FORBID_CALL_F(obj, func)                                   \
  TROMPELOEIL_REQUIRE_CALL_T(obj, func, .TROMPELOEIL_TIMES(0))

// Accept three or more arguments.
#define TROMPELOEIL_FORBID_CALL_T(obj, func, ...)                              \
  TROMPELOEIL_REQUIRE_CALL_T(obj,                                              \
                             func,                                             \
                             .TROMPELOEIL_TIMES(0) __VA_ARGS__)


#define TROMPELOEIL_NAMED_FORBID_CALL_V(...)                                   \
  TROMPELOEIL_IDENTITY(TROMPELOEIL_NAMED_FORBID_CALL_IMPL TROMPELOEIL_LPAREN   \
    TROMPELOEIL_MORE_THAN_TWO_ARGS(__VA_ARGS__), __VA_ARGS__))

// Dispatch to _F (0, 1, or 2 arguments) or _T (> 2 arguments) macro
#define TROMPELOEIL_NAMED_FORBID_CALL_IMPL(N, ...)                             \
  TROMPELOEIL_IDENTITY(                                                        \
    TROMPELOEIL_NAMED_FORBID_CALL_ ## N TROMPELOEIL_LPAREN __VA_ARGS__))

// Accept only two arguments
#define TROMPELOEIL_NAMED_FORBID_CALL_F(obj, func)                             \
  TROMPELOEIL_NAMED_REQUIRE_CALL_T(obj, func, .TROMPELOEIL_TIMES(0))

// Accept three or more arguments.
#define TROMPELOEIL_NAMED_FORBID_CALL_T(obj, func, ...)                        \
  TROMPELOEIL_NAMED_REQUIRE_CALL_T(obj,                                        \
                                   func,                                       \
                                   .TROMPELOEIL_TIMES(0) __VA_ARGS__)


#if (TROMPELOEIL_CPLUSPLUS > 201103L)

#define TROMPELOEIL_REQUIRE_CALL(obj, func)                                    \
  TROMPELOEIL_REQUIRE_CALL_(obj, func, #obj, #func)

#define TROMPELOEIL_REQUIRE_CALL_(obj, func, obj_s, func_s)                    \
  auto TROMPELOEIL_COUNT_ID(call_obj) = TROMPELOEIL_REQUIRE_CALL_OBJ(obj, func,\
                                                               obj_s, func_s)

#define TROMPELOEIL_NAMED_REQUIRE_CALL(obj, func)                              \
  TROMPELOEIL_NAMED_REQUIRE_CALL_(obj, func, #obj, #func)

#define TROMPELOEIL_NAMED_REQUIRE_CALL_(obj, func, obj_s, func_s)              \
  TROMPELOEIL_REQUIRE_CALL_OBJ(obj, func, obj_s, func_s)


#define TROMPELOEIL_REQUIRE_CALL_OBJ(obj, func, obj_s, func_s)                 \
  ::trompeloeil::call_validator_t<decltype((obj).TROMPELOEIL_CONCAT(trompeloeil_self_, func))>{(obj)} + \
    ::trompeloeil::detail::conditional_t<false,                                \
                       decltype((obj).func),                                   \
                       decltype((obj).TROMPELOEIL_CONCAT(trompeloeil_tag_,func))>\
    {__FILE__, static_cast<unsigned long>(__LINE__), obj_s "." func_s}.func


#define TROMPELOEIL_ALLOW_CALL(obj, func)                                      \
  TROMPELOEIL_ALLOW_CALL_(obj, func, #obj, #func)

#define TROMPELOEIL_ALLOW_CALL_(obj, func, obj_s, func_s)                      \
  TROMPELOEIL_REQUIRE_CALL_(obj, func, obj_s, func_s)                          \
    .TROMPELOEIL_INFINITY_TIMES()


#define TROMPELOEIL_NAMED_ALLOW_CALL(obj, func)                                \
  TROMPELOEIL_NAMED_ALLOW_CALL_(obj, func, #obj, #func)

#define TROMPELOEIL_NAMED_ALLOW_CALL_(obj, func, obj_s, func_s)                \
  TROMPELOEIL_NAMED_REQUIRE_CALL_(obj, func, obj_s, func_s)                    \
    .TROMPELOEIL_INFINITY_TIMES()


#define TROMPELOEIL_FORBID_CALL(obj, func)                                     \
  TROMPELOEIL_FORBID_CALL_(obj, func, #obj, #func)

#define TROMPELOEIL_FORBID_CALL_(obj, func, obj_s, func_s)                     \
  TROMPELOEIL_REQUIRE_CALL_(obj, func, obj_s, func_s)                          \
    .TROMPELOEIL_TIMES(0)


#define TROMPELOEIL_NAMED_FORBID_CALL(obj, func)                               \
  TROMPELOEIL_NAMED_FORBID_CALL_(obj, func, #obj, #func)

#define TROMPELOEIL_NAMED_FORBID_CALL_(obj, func, obj_s, func_s)               \
  TROMPELOEIL_NAMED_REQUIRE_CALL_(obj, func, obj_s, func_s)                    \
    .TROMPELOEIL_TIMES(0)

#endif /* (TROMPELOEIL_CPLUSPLUS > 201103L) */


#define TROMPELOEIL_WITH(...)    TROMPELOEIL_WITH_(=,#__VA_ARGS__, __VA_ARGS__)
#define TROMPELOEIL_LR_WITH(...) TROMPELOEIL_WITH_(&,#__VA_ARGS__, __VA_ARGS__)


#if (TROMPELOEIL_CPLUSPLUS == 201103L)

#define TROMPELOEIL_WITH_(capture, arg_s, ...)                                 \
  with(                                                                        \
    arg_s,                                                                     \
    [capture]                                                                  \
    (typename trompeloeil_e_t::trompeloeil_call_params_type_t const& trompeloeil_x)\
    {                                                                          \
      auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                      \
      auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                      \
      auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                      \
      auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                      \
      auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                      \
      auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                      \
      auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                      \
      auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                      \
      auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                      \
      auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                     \
      auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                     \
      auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                     \
      auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                     \
      auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                     \
      auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                     \
      ::trompeloeil::ignore(                                                   \
        _1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15);                   \
      return __VA_ARGS__;                                                      \
    })

#else /* (TROMPELOEIL_CPLUSPLUS == 201103L) */

#define TROMPELOEIL_WITH_(capture, arg_s, ...)                                 \
  with(arg_s, [capture](auto const& trompeloeil_x) {                           \
    auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                        \
    auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                        \
    auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                        \
    auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                        \
    auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                        \
    auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                        \
    auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                        \
    auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                        \
    auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                        \
    auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                       \
    auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                       \
    auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                       \
    auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                       \
    auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                       \
    auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                       \
    ::trompeloeil::ignore(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15); \
    return __VA_ARGS__;                                                        \
  })

#endif /* !(TROMPELOEIL_CPLUSPLUS == 201103L) */


#define TROMPELOEIL_SIDE_EFFECT(...)    TROMPELOEIL_SIDE_EFFECT_(=, __VA_ARGS__)
#define TROMPELOEIL_LR_SIDE_EFFECT(...) TROMPELOEIL_SIDE_EFFECT_(&, __VA_ARGS__)


#if (TROMPELOEIL_CPLUSPLUS == 201103L)

#define TROMPELOEIL_SIDE_EFFECT_(capture, ...)                                 \
  sideeffect(                                                                  \
    [capture]                                                                  \
    (typename trompeloeil_e_t::trompeloeil_call_params_type_t& trompeloeil_x)  \
    {                                                                          \
      auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                      \
      auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                      \
      auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                      \
      auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                      \
      auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                      \
      auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                      \
      auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                      \
      auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                      \
      auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                      \
      auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                     \
      auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                     \
      auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                     \
      auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                     \
      auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                     \
      auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                     \
      ::trompeloeil::ignore(                                                   \
        _1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15);                   \
      __VA_ARGS__;                                                             \
    })

#else /* (TROMPELOEIL_CPLUSPLUS == 201103L) */

#define TROMPELOEIL_SIDE_EFFECT_(capture, ...)                                 \
  sideeffect([capture](auto& trompeloeil_x) {                                  \
    auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                        \
    auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                        \
    auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                        \
    auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                        \
    auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                        \
    auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                        \
    auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                        \
    auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                        \
    auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                        \
    auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                       \
    auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                       \
    auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                       \
    auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                       \
    auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                       \
    auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                       \
    ::trompeloeil::ignore(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15); \
    __VA_ARGS__;                                                               \
  })

#endif /* !(TROMPELOEIL_CPLUSPLUS == 201103L) */


#define TROMPELOEIL_RETURN(...)    TROMPELOEIL_RETURN_(=, __VA_ARGS__)
#define TROMPELOEIL_LR_RETURN(...) TROMPELOEIL_RETURN_(&, __VA_ARGS__)


#if (TROMPELOEIL_CPLUSPLUS == 201103L)

#define TROMPELOEIL_RETURN_(capture, ...)                                      \
  handle_return(                                                               \
    [capture]                                                                  \
    (typename trompeloeil_e_t::trompeloeil_call_params_type_t& trompeloeil_x)  \
      -> typename trompeloeil_e_t::trompeloeil_return_of_t                     \
    {                                                                          \
      auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                      \
      auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                      \
      auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                      \
      auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                      \
      auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                      \
      auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                      \
      auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                      \
      auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                      \
      auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                      \
      auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                     \
      auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                     \
      auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                     \
      auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                     \
      auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                     \
      auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                     \
      ::trompeloeil::ignore(                                                   \
        _1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15);                   \
      return ::trompeloeil::decay_return_type(__VA_ARGS__);                    \
    })

#else /* (TROMPELOEIL_CPLUSPLUS == 201103L) */

#define TROMPELOEIL_RETURN_(capture, ...)                                      \
  handle_return([capture](auto& trompeloeil_x) -> decltype(auto) {             \
    auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                        \
    auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                        \
    auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                        \
    auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                        \
    auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                        \
    auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                        \
    auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                        \
    auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                        \
    auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                        \
    auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                       \
    auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                       \
    auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                       \
    auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                       \
    auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                       \
    auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                       \
    ::trompeloeil::ignore(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15); \
    return ::trompeloeil::decay_return_type(__VA_ARGS__);                      \
  })

#endif /* !(TROMPELOEIL_CPLUSPLUS == 201103L) */


#define TROMPELOEIL_THROW(...)    TROMPELOEIL_THROW_(=, __VA_ARGS__)
#define TROMPELOEIL_LR_THROW(...) TROMPELOEIL_THROW_(&, __VA_ARGS__)


#if (TROMPELOEIL_CPLUSPLUS == 201103L)

#define TROMPELOEIL_THROW_(capture, ...)                                       \
  handle_throw(                                                                \
    [capture]                                                                  \
    (typename trompeloeil_e_t::trompeloeil_call_params_type_t& trompeloeil_x)  \
    {                                                                          \
      auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                      \
      auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                      \
      auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                      \
      auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                      \
      auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                      \
      auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                      \
      auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                      \
      auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                      \
      auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                      \
      auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                     \
      auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                     \
      auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                     \
      auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                     \
      auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                     \
      auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                     \
      ::trompeloeil::ignore(                                                   \
        _1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15);                   \
      throw __VA_ARGS__;                                                       \
    })

#else /* (TROMPELOEIL_CPLUSPLUS == 201103L) */

#define TROMPELOEIL_THROW_(capture, ...)                                       \
  handle_throw([capture](auto& trompeloeil_x)  {                               \
    auto&& _1 = ::trompeloeil::mkarg<1>(trompeloeil_x);                        \
    auto&& _2 = ::trompeloeil::mkarg<2>(trompeloeil_x);                        \
    auto&& _3 = ::trompeloeil::mkarg<3>(trompeloeil_x);                        \
    auto&& _4 = ::trompeloeil::mkarg<4>(trompeloeil_x);                        \
    auto&& _5 = ::trompeloeil::mkarg<5>(trompeloeil_x);                        \
    auto&& _6 = ::trompeloeil::mkarg<6>(trompeloeil_x);                        \
    auto&& _7 = ::trompeloeil::mkarg<7>(trompeloeil_x);                        \
    auto&& _8 = ::trompeloeil::mkarg<8>(trompeloeil_x);                        \
    auto&& _9 = ::trompeloeil::mkarg<9>(trompeloeil_x);                        \
    auto&&_10 = ::trompeloeil::mkarg<10>(trompeloeil_x);                       \
    auto&&_11 = ::trompeloeil::mkarg<11>(trompeloeil_x);                       \
    auto&&_12 = ::trompeloeil::mkarg<12>(trompeloeil_x);                       \
    auto&&_13 = ::trompeloeil::mkarg<13>(trompeloeil_x);                       \
    auto&&_14 = ::trompeloeil::mkarg<14>(trompeloeil_x);                       \
    auto&&_15 = ::trompeloeil::mkarg<15>(trompeloeil_x);                       \
    ::trompeloeil::ignore(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15); \
    throw __VA_ARGS__;                                                         \
 })

#endif /* !(TROMPELOEIL_CPLUSPLUS == 201103L) */


#define TROMPELOEIL_TIMES(...) times(::trompeloeil::multiplicity<__VA_ARGS__>{})
#define TROMPELOEIL_INFINITY_TIMES() TROMPELOEIL_TIMES(0, ~static_cast<size_t>(0))

#define TROMPELOEIL_IN_SEQUENCE(...)                                           \
  in_sequence(TROMPELOEIL_INIT_WITH_STR(::trompeloeil::sequence_matcher::init_type, __VA_ARGS__))

#define TROMPELOEIL_ANY(type) ::trompeloeil::any_matcher<type>(#type)

#define TROMPELOEIL_AT_LEAST(num) num, ~static_cast<size_t>(0)
#define TROMPELOEIL_AT_MOST(num) 0, num

#define TROMPELOEIL_REQUIRE_DESTRUCTION(obj)                                   \
  TROMPELOEIL_REQUIRE_DESTRUCTION_(obj, #obj)

#define TROMPELOEIL_REQUIRE_DESTRUCTION_(obj, obj_s)                           \
  std::unique_ptr<trompeloeil::expectation>                                    \
    TROMPELOEIL_CONCAT(trompeloeil_death_monitor_, __LINE__)                   \
    = TROMPELOEIL_NAMED_REQUIRE_DESTRUCTION_(,obj, obj_s)

#define TROMPELOEIL_NAMED_REQUIRE_DESTRUCTION(obj)                             \
  TROMPELOEIL_NAMED_REQUIRE_DESTRUCTION_("NAMED_", obj, #obj)

#define TROMPELOEIL_NAMED_REQUIRE_DESTRUCTION_(prefix, obj, obj_s)             \
  trompeloeil::lifetime_monitor_releaser{} +                                   \
  trompeloeil::lifetime_monitor_modifier<false>{                               \
    ::trompeloeil::detail::make_unique<trompeloeil::lifetime_monitor>(         \
      obj,                                                                     \
      obj_s,                                                                   \
      prefix "REQUIRE_DESTRUCTION(" obj_s ")",                                 \
      "destructor for " obj_s,                                                 \
      ::trompeloeil::location{__FILE__,                                        \
                              static_cast<unsigned long>(__LINE__)})           \
  }

#ifndef TROMPELOEIL_LONG_MACROS
#define MAKE_MOCK0                TROMPELOEIL_MAKE_MOCK0
#define MAKE_MOCK1                TROMPELOEIL_MAKE_MOCK1
#define MAKE_MOCK2                TROMPELOEIL_MAKE_MOCK2
#define MAKE_MOCK3                TROMPELOEIL_MAKE_MOCK3
#define MAKE_MOCK4                TROMPELOEIL_MAKE_MOCK4
#define MAKE_MOCK5                TROMPELOEIL_MAKE_MOCK5
#define MAKE_MOCK6                TROMPELOEIL_MAKE_MOCK6
#define MAKE_MOCK7                TROMPELOEIL_MAKE_MOCK7
#define MAKE_MOCK8                TROMPELOEIL_MAKE_MOCK8
#define MAKE_MOCK9                TROMPELOEIL_MAKE_MOCK9
#define MAKE_MOCK10               TROMPELOEIL_MAKE_MOCK10
#define MAKE_MOCK11               TROMPELOEIL_MAKE_MOCK11
#define MAKE_MOCK12               TROMPELOEIL_MAKE_MOCK12
#define MAKE_MOCK13               TROMPELOEIL_MAKE_MOCK13
#define MAKE_MOCK14               TROMPELOEIL_MAKE_MOCK14
#define MAKE_MOCK15               TROMPELOEIL_MAKE_MOCK15

#define MAKE_CONST_MOCK0          TROMPELOEIL_MAKE_CONST_MOCK0
#define MAKE_CONST_MOCK1          TROMPELOEIL_MAKE_CONST_MOCK1
#define MAKE_CONST_MOCK2          TROMPELOEIL_MAKE_CONST_MOCK2
#define MAKE_CONST_MOCK3          TROMPELOEIL_MAKE_CONST_MOCK3
#define MAKE_CONST_MOCK4          TROMPELOEIL_MAKE_CONST_MOCK4
#define MAKE_CONST_MOCK5          TROMPELOEIL_MAKE_CONST_MOCK5
#define MAKE_CONST_MOCK6          TROMPELOEIL_MAKE_CONST_MOCK6
#define MAKE_CONST_MOCK7          TROMPELOEIL_MAKE_CONST_MOCK7
#define MAKE_CONST_MOCK8          TROMPELOEIL_MAKE_CONST_MOCK8
#define MAKE_CONST_MOCK9          TROMPELOEIL_MAKE_CONST_MOCK9
#define MAKE_CONST_MOCK10         TROMPELOEIL_MAKE_CONST_MOCK10
#define MAKE_CONST_MOCK11         TROMPELOEIL_MAKE_CONST_MOCK11
#define MAKE_CONST_MOCK12         TROMPELOEIL_MAKE_CONST_MOCK12
#define MAKE_CONST_MOCK13         TROMPELOEIL_MAKE_CONST_MOCK13
#define MAKE_CONST_MOCK14         TROMPELOEIL_MAKE_CONST_MOCK14
#define MAKE_CONST_MOCK15         TROMPELOEIL_MAKE_CONST_MOCK15

#define IMPLEMENT_MOCK0           TROMPELOEIL_IMPLEMENT_MOCK0
#define IMPLEMENT_MOCK1           TROMPELOEIL_IMPLEMENT_MOCK1
#define IMPLEMENT_MOCK2           TROMPELOEIL_IMPLEMENT_MOCK2
#define IMPLEMENT_MOCK3           TROMPELOEIL_IMPLEMENT_MOCK3
#define IMPLEMENT_MOCK4           TROMPELOEIL_IMPLEMENT_MOCK4
#define IMPLEMENT_MOCK5           TROMPELOEIL_IMPLEMENT_MOCK5
#define IMPLEMENT_MOCK6           TROMPELOEIL_IMPLEMENT_MOCK6
#define IMPLEMENT_MOCK7           TROMPELOEIL_IMPLEMENT_MOCK7
#define IMPLEMENT_MOCK8           TROMPELOEIL_IMPLEMENT_MOCK8
#define IMPLEMENT_MOCK9           TROMPELOEIL_IMPLEMENT_MOCK9
#define IMPLEMENT_MOCK10          TROMPELOEIL_IMPLEMENT_MOCK10
#define IMPLEMENT_MOCK11          TROMPELOEIL_IMPLEMENT_MOCK11
#define IMPLEMENT_MOCK12          TROMPELOEIL_IMPLEMENT_MOCK12
#define IMPLEMENT_MOCK13          TROMPELOEIL_IMPLEMENT_MOCK13
#define IMPLEMENT_MOCK14          TROMPELOEIL_IMPLEMENT_MOCK14
#define IMPLEMENT_MOCK15          TROMPELOEIL_IMPLEMENT_MOCK15

#define IMPLEMENT_CONST_MOCK0     TROMPELOEIL_IMPLEMENT_CONST_MOCK0
#define IMPLEMENT_CONST_MOCK1     TROMPELOEIL_IMPLEMENT_CONST_MOCK1
#define IMPLEMENT_CONST_MOCK2     TROMPELOEIL_IMPLEMENT_CONST_MOCK2
#define IMPLEMENT_CONST_MOCK3     TROMPELOEIL_IMPLEMENT_CONST_MOCK3
#define IMPLEMENT_CONST_MOCK4     TROMPELOEIL_IMPLEMENT_CONST_MOCK4
#define IMPLEMENT_CONST_MOCK5     TROMPELOEIL_IMPLEMENT_CONST_MOCK5
#define IMPLEMENT_CONST_MOCK6     TROMPELOEIL_IMPLEMENT_CONST_MOCK6
#define IMPLEMENT_CONST_MOCK7     TROMPELOEIL_IMPLEMENT_CONST_MOCK7
#define IMPLEMENT_CONST_MOCK8     TROMPELOEIL_IMPLEMENT_CONST_MOCK8
#define IMPLEMENT_CONST_MOCK9     TROMPELOEIL_IMPLEMENT_CONST_MOCK9
#define IMPLEMENT_CONST_MOCK10    TROMPELOEIL_IMPLEMENT_CONST_MOCK10
#define IMPLEMENT_CONST_MOCK11    TROMPELOEIL_IMPLEMENT_CONST_MOCK11
#define IMPLEMENT_CONST_MOCK12    TROMPELOEIL_IMPLEMENT_CONST_MOCK12
#define IMPLEMENT_CONST_MOCK13    TROMPELOEIL_IMPLEMENT_CONST_MOCK13
#define IMPLEMENT_CONST_MOCK14    TROMPELOEIL_IMPLEMENT_CONST_MOCK14
#define IMPLEMENT_CONST_MOCK15    TROMPELOEIL_IMPLEMENT_CONST_MOCK15

#define REQUIRE_CALL_V            TROMPELOEIL_REQUIRE_CALL_V
#define NAMED_REQUIRE_CALL_V      TROMPELOEIL_NAMED_REQUIRE_CALL_V
#define ALLOW_CALL_V              TROMPELOEIL_ALLOW_CALL_V
#define NAMED_ALLOW_CALL_V        TROMPELOEIL_NAMED_ALLOW_CALL_V
#define FORBID_CALL_V             TROMPELOEIL_FORBID_CALL_V
#define NAMED_FORBID_CALL_V       TROMPELOEIL_NAMED_FORBID_CALL_V

#if (TROMPELOEIL_CPLUSPLUS > 201103L)

#define REQUIRE_CALL              TROMPELOEIL_REQUIRE_CALL
#define NAMED_REQUIRE_CALL        TROMPELOEIL_NAMED_REQUIRE_CALL
#define ALLOW_CALL                TROMPELOEIL_ALLOW_CALL
#define NAMED_ALLOW_CALL          TROMPELOEIL_NAMED_ALLOW_CALL
#define FORBID_CALL               TROMPELOEIL_FORBID_CALL
#define NAMED_FORBID_CALL         TROMPELOEIL_NAMED_FORBID_CALL

#endif /* (TROMPELOEIL_CPLUSPLUS > 201103L) */

#define WITH                      TROMPELOEIL_WITH
#define LR_WITH                   TROMPELOEIL_LR_WITH
#define SIDE_EFFECT               TROMPELOEIL_SIDE_EFFECT
#define LR_SIDE_EFFECT            TROMPELOEIL_LR_SIDE_EFFECT
#define RETURN                    TROMPELOEIL_RETURN
#define LR_RETURN                 TROMPELOEIL_LR_RETURN
#define THROW                     TROMPELOEIL_THROW
#define LR_THROW                  TROMPELOEIL_LR_THROW

#define TIMES                     TROMPELOEIL_TIMES
#define IN_SEQUENCE               TROMPELOEIL_IN_SEQUENCE
#define ANY                       TROMPELOEIL_ANY
#define AT_LEAST                  TROMPELOEIL_AT_LEAST
#define AT_MOST                   TROMPELOEIL_AT_MOST
#define REQUIRE_DESTRUCTION       TROMPELOEIL_REQUIRE_DESTRUCTION
#define NAMED_REQUIRE_DESTRUCTION TROMPELOEIL_NAMED_REQUIRE_DESTRUCTION

#endif // TROMPELOEIL_LONG_MACROS

#endif // include guard