Knowledge

Functional (C++)

Source đź“ť

347:
may be overloaded or may be a member template. Similarly, there need be no way for a program to determine what those restrictions are. An adaptable function object, however, does specify what the argument and return types are, and provides nested ]s so that those types can be named and used in
453:
Adaptable function objects are important, because they can be used by function object adaptors: function objects that transform or manipulate other function objects. The C++ Standard Library provides many different function object adaptors, including
265:. It is possible to perform very sophisticated operations without writing a new function object, simply by combining predefined function objects and function object adaptors. 210: 75: 338:
In general, a function object has restrictions on the type of its argument. The type restrictions need not be simple, though:
302:
provided by the C++ Standard Library do not require function objects of more than two arguments. Function objects that return
1810: 203: 585:
Function wrappers can be used to make calls to ordinary functions or to functions objects created by lambda expressions.
1849: 277: 196: 70: 56: 291:), bind expressions (instances of function adapters that transform functions to other functions of smaller 262: 258: 128: 98: 65: 249:, including operations for arithmetic, comparisons, and logic. Instances of these class templates are 460:(that returns the logical complement of the value returned by a particular adaptable predicate), and 118: 287:
can store, copy, and invoke any callable target—functions, lambda expressions (expressions defining
123: 108: 254: 238: 19: 33: 143: 28: 8: 113: 450:
to simplify the definition of adaptable unary functions and adaptable binary functions.
288: 84: 1806: 1799: 303: 299: 138: 133: 103: 39: 280: 1113: 1109: 246: 1844: 307: 242: 1829: 1838: 487:
many different predefined function objects, including arithmetic operations (
250: 295:
by providing values for some of the arguments), or other function objects.
93: 481: 234: 1469:/* A function wrapper to member function without parameter passing */ 1574:/* A function wrapper to member function with passing a parameter */ 180: 171: 153: 1667:/* A function wrapper to member function generated by std::bind */ 273: 162: 292: 224: 402:
is a model of the adaptable binary function, it must define
372:
is a model of the adaptable unary function, it must define
354:
is a model of an adaptable generator, then it must define
1337:/* A function wrapper to a member variable of a class */ 1798: 438:. The C++ Standard Library provides base classes 1836: 472:, which perform composition of function object. 1004:/* A function wrapper generated by std::bind(). 917:/* A function wrapper generated by std::bind(). 261:of these classes can be called as if they were 1792: 1790: 821:/* A function wrapper to a lambda function. */ 755:/* A function wrapper to a function pointer */ 475: 1108:Function wrappers also can be used to access 1007:* Pass a parameter when calling the function. 333: 320:, and a binary function whose return type is 204: 920:* Pass a pre-defined parameter when binding. 1830:C++ reference for standard function objects 1787: 223:In the context of the programming language 211: 197: 480:The C++ Standard Library includes in the 1796: 306:values are an important special case. A 1837: 692:/* A function wrapper to a function */ 13: 14: 1861: 1823: 241:and provides a set of predefined 602:/* Define a template function */ 76:Unordered associative containers 1: 1797:Josuttis, Nicolai M. (1999). 1780: 7: 580: 559:), and logical operations ( 476:Predefined function objects 10: 1866: 334:Adaptable function objects 572: 566: 560: 554: 548: 542: 536: 530: 524: 518: 512: 506: 500: 494: 488: 467: 461: 455: 445: 439: 427: 415: 403: 397: 385: 373: 367: 355: 349: 339: 321: 311: 1801:The C++ Standard Library 1118: 587: 99:Character classification 148:Miscellaneous headers: 255:function call operator 71:Associative containers 310:whose return type is 276:is a general-purpose 1850:C++ Standard Library 423:second_argument_type 348:programs. If a type 239:C++ Standard Library 237:that is part of the 20:C++ Standard Library 411:first_argument_type 289:anonymous functions 268:The class template 66:Sequence containers 1805:. Addison-Wesley. 1130:<functional> 599:<functional> 144:Alternative tokens 85:C standard library 1812:978-0-201-37926-6 992:"PI is" 221: 220: 129:Memory allocation 114:File input/output 1857: 1817: 1816: 1804: 1794: 1776: 1773: 1770: 1767: 1764: 1761: 1758: 1755: 1752: 1749: 1746: 1743: 1740: 1737: 1734: 1731: 1728: 1725: 1722: 1719: 1716: 1713: 1710: 1707: 1704: 1701: 1698: 1695: 1692: 1689: 1686: 1683: 1680: 1677: 1674: 1671: 1668: 1665: 1662: 1659: 1656: 1653: 1650: 1647: 1644: 1641: 1638: 1635: 1632: 1629: 1626: 1623: 1620: 1617: 1614: 1611: 1608: 1605: 1602: 1599: 1596: 1593: 1590: 1587: 1584: 1581: 1578: 1575: 1572: 1569: 1566: 1563: 1560: 1557: 1554: 1551: 1548: 1545: 1542: 1539: 1536: 1533: 1530: 1527: 1524: 1521: 1518: 1515: 1512: 1509: 1506: 1503: 1500: 1497: 1494: 1491: 1488: 1485: 1482: 1479: 1476: 1473: 1470: 1467: 1464: 1461: 1458: 1455: 1452: 1449: 1446: 1443: 1440: 1437: 1434: 1431: 1428: 1425: 1422: 1419: 1416: 1413: 1410: 1407: 1404: 1401: 1398: 1395: 1392: 1389: 1386: 1383: 1380: 1377: 1374: 1371: 1368: 1365: 1362: 1359: 1356: 1353: 1350: 1347: 1344: 1341: 1338: 1335: 1332: 1329: 1326: 1323: 1320: 1317: 1314: 1311: 1308: 1305: 1302: 1299: 1296: 1293: 1290: 1287: 1284: 1281: 1278: 1275: 1272: 1269: 1266: 1263: 1260: 1257: 1254: 1251: 1248: 1245: 1242: 1239: 1236: 1233: 1230: 1227: 1224: 1221: 1218: 1215: 1212: 1209: 1206: 1203: 1200: 1197: 1194: 1191: 1188: 1185: 1182: 1179: 1176: 1173: 1170: 1167: 1164: 1161: 1158: 1155: 1152: 1149: 1146: 1143: 1140: 1137: 1134: 1131: 1128: 1125: 1124:<iostream> 1122: 1114:member functions 1110:member variables 1104: 1101: 1098: 1095: 1092: 1089: 1086: 1083: 1080: 1077: 1074: 1071: 1068: 1065: 1062: 1059: 1056: 1053: 1050: 1047: 1044: 1041: 1038: 1035: 1032: 1029: 1026: 1023: 1020: 1017: 1014: 1011: 1008: 1005: 1002: 999: 996: 993: 990: 987: 984: 981: 978: 975: 972: 969: 966: 963: 960: 957: 954: 951: 948: 945: 942: 939: 936: 933: 930: 927: 924: 921: 918: 915: 912: 909: 906: 903: 900: 897: 894: 891: 888: 885: 882: 879: 876: 873: 870: 867: 864: 861: 858: 855: 852: 849: 846: 843: 840: 837: 834: 831: 828: 825: 822: 819: 816: 813: 810: 807: 804: 801: 798: 795: 792: 789: 786: 783: 780: 777: 774: 771: 768: 765: 762: 759: 756: 753: 750: 747: 744: 741: 738: 735: 732: 729: 726: 723: 720: 717: 714: 711: 708: 705: 702: 699: 696: 693: 690: 687: 684: 681: 678: 675: 672: 669: 666: 663: 660: 657: 654: 651: 648: 645: 642: 639: 636: 633: 630: 627: 624: 621: 618: 615: 612: 609: 606: 603: 600: 597: 594: 593:<iostream> 591: 576: 575: 570: 569: 564: 563: 558: 557: 552: 551: 546: 545: 540: 539: 534: 533: 528: 527: 523:), comparisons ( 522: 521: 516: 515: 510: 509: 504: 503: 498: 497: 492: 491: 486: 471: 470: 465: 464: 459: 458: 449: 448: 443: 442: 437: 436: 433: 430: 425: 424: 421: 418: 413: 412: 409: 406: 401: 400: 395: 394: 391: 388: 383: 382: 379: 376: 371: 370: 366:. Similarly, if 365: 364: 361: 358: 353: 352: 346: 345: 342: 328:binary predicate 325: 324: 315: 314: 286: 281:function wrapper 271: 247:function objects 231: 213: 206: 199: 184: 175: 166: 157: 49: 42: 16: 15: 1865: 1864: 1860: 1859: 1858: 1856: 1855: 1854: 1835: 1834: 1826: 1821: 1820: 1813: 1795: 1788: 1783: 1778: 1777: 1774: 1771: 1768: 1765: 1762: 1759: 1756: 1753: 1750: 1747: 1744: 1741: 1738: 1735: 1732: 1729: 1726: 1723: 1720: 1717: 1714: 1711: 1708: 1705: 1702: 1699: 1696: 1693: 1690: 1687: 1684: 1681: 1678: 1675: 1672: 1669: 1666: 1663: 1660: 1657: 1654: 1651: 1648: 1645: 1642: 1639: 1636: 1633: 1630: 1627: 1624: 1621: 1618: 1615: 1612: 1609: 1606: 1603: 1600: 1597: 1594: 1591: 1588: 1585: 1582: 1579: 1576: 1573: 1570: 1567: 1564: 1561: 1558: 1555: 1552: 1549: 1546: 1543: 1540: 1537: 1534: 1531: 1528: 1525: 1522: 1519: 1516: 1513: 1510: 1507: 1504: 1501: 1498: 1495: 1492: 1489: 1486: 1483: 1480: 1477: 1474: 1471: 1468: 1465: 1462: 1459: 1456: 1453: 1450: 1447: 1444: 1441: 1438: 1435: 1432: 1429: 1426: 1423: 1420: 1417: 1414: 1411: 1408: 1405: 1402: 1399: 1396: 1393: 1390: 1387: 1384: 1381: 1378: 1375: 1372: 1369: 1366: 1363: 1360: 1357: 1354: 1351: 1348: 1345: 1342: 1339: 1336: 1333: 1330: 1327: 1324: 1321: 1318: 1315: 1312: 1309: 1306: 1303: 1300: 1297: 1294: 1291: 1288: 1285: 1282: 1279: 1276: 1273: 1270: 1267: 1264: 1261: 1258: 1255: 1252: 1249: 1246: 1243: 1240: 1237: 1234: 1231: 1228: 1225: 1222: 1219: 1216: 1213: 1210: 1207: 1204: 1201: 1198: 1195: 1192: 1189: 1186: 1183: 1180: 1177: 1174: 1171: 1168: 1165: 1162: 1159: 1156: 1153: 1150: 1147: 1144: 1141: 1138: 1135: 1132: 1129: 1126: 1123: 1120: 1106: 1105: 1102: 1099: 1096: 1093: 1090: 1087: 1084: 1081: 1078: 1075: 1072: 1069: 1066: 1063: 1060: 1057: 1054: 1051: 1048: 1045: 1042: 1039: 1036: 1033: 1030: 1027: 1024: 1021: 1018: 1015: 1012: 1009: 1006: 1003: 1000: 997: 994: 991: 988: 985: 982: 979: 976: 973: 970: 967: 964: 961: 958: 955: 952: 949: 946: 943: 940: 937: 934: 931: 928: 925: 922: 919: 916: 913: 910: 907: 904: 901: 898: 895: 892: 889: 886: 883: 880: 877: 874: 871: 868: 865: 862: 859: 856: 853: 850: 847: 844: 841: 838: 835: 832: 829: 826: 823: 820: 817: 814: 811: 808: 805: 802: 799: 796: 793: 790: 787: 784: 781: 778: 775: 772: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 739: 736: 733: 730: 727: 724: 721: 718: 715: 712: 709: 706: 703: 700: 697: 694: 691: 688: 685: 682: 679: 676: 673: 670: 667: 664: 661: 658: 655: 652: 649: 646: 643: 640: 637: 634: 631: 628: 625: 622: 619: 616: 613: 610: 607: 604: 601: 598: 595: 592: 589: 583: 573: 567: 561: 555: 549: 543: 537: 531: 525: 519: 513: 507: 501: 495: 489: 484: 478: 468: 462: 456: 447:binary_function 446: 440: 434: 431: 428: 422: 419: 416: 410: 407: 404: 398: 392: 389: 386: 380: 377: 374: 368: 362: 359: 356: 350: 343: 340: 336: 322: 312: 284: 283:. Instances of 269: 243:class templates 229: 217: 178: 169: 160: 151: 134:Process control 45: 38: 12: 11: 5: 1863: 1853: 1852: 1847: 1833: 1832: 1825: 1824:External links 1822: 1819: 1818: 1811: 1785: 1784: 1782: 1779: 1119: 588: 582: 579: 477: 474: 469:binary_compose 441:unary_function 335: 332: 308:unary function 253:that define a 219: 218: 216: 215: 208: 201: 193: 190: 189: 188: 187: 186: 185: 176: 167: 158: 146: 141: 136: 131: 126: 121: 116: 111: 106: 101: 96: 88: 87: 81: 80: 79: 78: 73: 68: 60: 59: 53: 52: 51: 50: 43: 36: 31: 23: 22: 9: 6: 4: 3: 2: 1862: 1851: 1848: 1846: 1843: 1842: 1840: 1831: 1828: 1827: 1814: 1808: 1803: 1802: 1793: 1791: 1786: 1730:PrintAfterAdd 1643:PrintAfterAdd 1250:PrintAfterAdd 1117: 1115: 1111: 586: 578: 550:greater_equal 483: 473: 463:unary_compose 451: 381:argument_type 331: 329: 319: 309: 305: 301: 296: 294: 290: 285:std::function 282: 279: 275: 270:std::function 266: 264: 260: 256: 252: 248: 244: 240: 236: 232: 226: 214: 209: 207: 202: 200: 195: 194: 192: 191: 182: 177: 173: 168: 164: 159: 155: 150: 149: 147: 145: 142: 140: 137: 135: 132: 130: 127: 125: 122: 120: 117: 115: 112: 110: 107: 105: 102: 100: 97: 95: 92: 91: 90: 89: 86: 83: 82: 77: 74: 72: 69: 67: 64: 63: 62: 61: 58: 55: 54: 48: 44: 41: 37: 35: 32: 30: 27: 26: 25: 24: 21: 18: 17: 1800: 1751:placeholders 1116:of classes. 1107: 1079:placeholders 584: 532:not_equal_to 479: 457:unary_negate 452: 337: 327: 326:is called a 317: 316:is called a 297: 272:provided by 267: 233:refers to a 228: 222: 124:Localization 46: 29:Input/output 574:logical_not 562:logical_and 482:header file 435:result_type 393:result_type 363:result_type 278:polymorphic 251:C++ classes 235:header file 109:Mathematics 1839:Categories 1781:References 1058:PrintValue 971:PrintValue 794:PrintValue 728:PrintValue 623:PrintValue 568:logical_or 556:less_equal 502:multiplies 485:functional 300:algorithms 257:, and the 230:functional 94:Data types 57:Containers 47:functional 396:, and if 318:predicate 263:functions 259:instances 119:Date/time 40:algorithm 1718:CAnyData 1676:function 1631:CAnyData 1595:CAnyData 1583:function 1544:CAnyData 1514:CAnyData 1502:function 1472:CAnyData 1454:<< 1439:<< 1412:CAnyData 1382:CAnyData 1370:function 1340:CAnyData 1295:<< 1277:<< 1229:<< 1223:<< 1163:CAnyData 1151:CAnyData 1139:typename 1133:template 1127:#include 1121:#include 1019:function 932:function 887:<< 881:<< 830:function 764:function 701:function 656:<< 650:<< 611:typename 605:template 596:#include 590:#include 581:Examples 526:equal_to 341:operator 181:stdarg.h 172:setjmp.h 154:assert.h 1424:m_value 1316:m_value 1283:m_value 1226:m_value 1181:m_value 1097:3.14159 538:greater 514:modulus 508:divides 304:Boolean 163:errno.h 139:Signals 104:Strings 34:Strings 1809:  1763:func_d 1739:data_b 1727:>:: 1697:func_d 1655:data_b 1649:func_c 1640:>:: 1622:func_c 1568:data_b 1562:func_b 1553:>:: 1535:func_b 1490:2016.1 1484:data_b 1448:data_a 1442:func_a 1421:>:: 1403:func_a 1352:data_a 1157:public 1091:func_e 1040:func_e 998:func_d 983:string 953:func_d 905:func_c 851:func_c 809:func_b 785:func_b 743:func_a 722:func_a 571:, and 553:, and 520:negate 517:, and 426:, and 1736:& 1724:float 1715:& 1688:float 1637:float 1628:& 1613:float 1607:& 1601:float 1556:Print 1550:float 1541:& 1526:& 1520:float 1478:float 1409:& 1394:& 1289:value 1259:value 1199:Print 1187:value 1172:value 1148:class 1064:float 1031:float 884:value 863:value 791:& 653:value 632:value 496:minus 293:arity 274:C++11 1807:ISBN 1721:< 1709:bind 1694:> 1682:void 1679:< 1634:< 1619:> 1604:> 1598:< 1589:void 1586:< 1547:< 1532:> 1523:> 1517:< 1508:void 1505:< 1481:> 1475:< 1463:endl 1436:cout 1415:< 1400:> 1391:> 1385:< 1373:< 1358:2016 1349:> 1343:< 1328:main 1304:endl 1274:cout 1247:void 1238:endl 1220:cout 1205:void 1196:void 1145:> 1136:< 1112:and 1067:> 1061:< 1052:bind 1037:> 1025:void 1022:< 986:> 974:< 965:bind 950:> 944:void 938:void 935:< 911:2017 896:endl 878:cout 848:> 836:void 833:< 815:2016 803:> 797:< 782:> 770:void 767:< 749:2015 737:> 731:< 719:> 707:void 704:< 683:void 677:main 665:endl 647:cout 620:void 617:> 608:< 544:less 490:plus 466:and 444:and 384:and 323:bool 313:bool 298:The 245:for 183:> 179:< 174:> 170:< 165:> 161:< 156:> 152:< 1845:C++ 1769:0.2 1745:std 1703:std 1670:std 1661:0.1 1577:std 1496:std 1457:std 1430:std 1418:int 1388:int 1376:int 1364:std 1346:int 1325:int 1298:std 1268:std 1232:std 1214:std 1073:std 1046:std 1013:std 1001:(); 977:std 959:std 926:std 890:std 872:std 860:int 842:int 824:std 800:int 776:int 758:std 734:int 713:int 695:std 674:int 659:std 641:std 577:). 225:C++ 1841:: 1789:^ 1772:); 1760:); 1757:_1 1754::: 1748::: 1706::: 1673::: 1664:); 1580::: 1571:); 1499::: 1493:}; 1460::: 1433::: 1367::: 1361:}; 1331:() 1322:}; 1301::: 1271::: 1235::: 1217::: 1193:{} 1100:); 1088:); 1085:_1 1082::: 1076::: 1049::: 1016::: 1010:*/ 995:); 980::: 962::: 929::: 923:*/ 914:); 902:}; 893::: 875::: 827::: 818:); 761::: 752:); 698::: 662::: 644::: 565:, 547:, 541:, 535:, 529:, 511:, 505:, 499:, 493:, 432::: 429:F2 420::: 417:F2 414:, 408::: 405:F2 399:F2 390::: 387:F1 378::: 375:F1 369:F1 360::: 357:F0 351:F0 344:() 330:. 227:, 1815:. 1775:} 1766:( 1742:, 1733:, 1712:( 1700:= 1691:) 1685:( 1658:, 1652:( 1646:; 1625:= 1616:) 1610:, 1592:( 1565:( 1559:; 1538:= 1529:) 1511:( 1487:{ 1466:; 1451:) 1445:( 1427:; 1406:= 1397:) 1379:( 1355:{ 1334:{ 1319:; 1313:T 1310:} 1307:; 1292:) 1286:+ 1280:( 1265:{ 1262:) 1256:T 1253:( 1244:} 1241:; 1211:{ 1208:) 1202:( 1190:} 1184:{ 1178:: 1175:) 1169:T 1166:( 1160:: 1154:{ 1142:T 1103:} 1094:( 1070:, 1055:( 1043:= 1034:) 1028:( 989:, 968:( 956:= 947:) 941:( 908:( 899:; 869:{ 866:) 857:( 854:= 845:) 839:( 812:( 806:; 788:= 779:) 773:( 746:( 740:; 725:= 716:) 710:( 689:{ 686:) 680:( 671:} 668:; 638:{ 635:) 629:T 626:( 614:T 212:e 205:t 198:v

Index

C++ Standard Library
Input/output
Strings
algorithm
functional
Containers
Sequence containers
Associative containers
Unordered associative containers
C standard library
Data types
Character classification
Strings
Mathematics
File input/output
Date/time
Localization
Memory allocation
Process control
Signals
Alternative tokens
assert.h
errno.h
setjmp.h
stdarg.h
v
t
e
C++
header file

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑