diff --git a/.travis.yml b/.travis.yml index 9a80acd6e..f474b634d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,30 @@ # Travis CI configuration file # http://about.travis-ci.org/docs/ -dist: trusty +dist: bionic language: python # Available Python versions: # http://about.travis-ci.org/docs/user/ci-environment/#Python-VM-images python: - - "3.5" - "3.6" + - "3.7" # Dependencies installation commands install: - pip install -U pip - pip install -r requirements.txt + - pip install -r requirements-ci.txt -#before_script: -# - "if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then flake8 --config=config/flake8rc asm_collect.py asmtest tests; fi" -# - "if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then pylint --rcfile=config/pylintrc asm_collect.py asmtest tests; fi" +before_script: + - "flake8 --config=config/flake8rc *.py commands index_transform gadgets/standard_revisions_tests/*.py tests" + - "pylint --rcfile=config/pylintrc *.py commands index_transform gadgets/standard_revisions_tests/*.py tests" script: - "python -m unittest discover" + - "mkdir -p tmp" + - "python index2browser.py index-functions-c.xml tmp/index-functions-c-web.html" + - "python index2browser.py index-functions-cpp.xml tmp/index-functions-cpp-web.html" notifications: email: false diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..f288702d2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Makefile b/Makefile index fe8ab3310..644e3a566 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ qhelpgenerator = qhelpgenerator #Version -VERSION=20180311 +VERSION=20190607 #STANDARD RULES @@ -175,13 +175,13 @@ output/cppreference-doc-en-cpp.devhelp2: \ #build the .qch (QT help) file output/cppreference-doc-en-cpp.qch: output/qch-help-project-cpp.xml #qhelpgenerator only works if the project file is in the same directory as the documentation - cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.xml" + cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.qhp" pushd "output/reference_cssless" > /dev/null; \ - $(qhelpgenerator) "qch.xml" -o "../cppreference-doc-en-cpp.qch"; \ + $(qhelpgenerator) "qch.qhp" -o "../cppreference-doc-en-cpp.qch"; \ popd > /dev/null - rm -f "output/reference_cssless/qch.xml" + rm -f "output/reference_cssless/qch.qhp" output/qch-help-project-cpp.xml: \ output/cppreference-doc-en-cpp.devhelp2 \ @@ -257,4 +257,4 @@ source: http://en.cppreference.com/w/ ; \ popd > /dev/null - ./export.py --url=http://en.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10 + ./export.py --url=https://en.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10 diff --git a/build_link_map.py b/build_link_map.py index 851c8ee1e..c5fa89092 100755 --- a/build_link_map.py +++ b/build_link_map.py @@ -21,10 +21,12 @@ # filename -> title mapping to a xml file. import fnmatch -import re import os +import re + from link_map import LinkMap + # returns a dict { title -> filename }. # directory - either 'output/reference' or 'reference' def build_link_map(directory): @@ -41,26 +43,30 @@ def build_link_map(directory): text = f.read() f.close() - m = re.search('', text) + m = re.search(r'', text) # noqa if not m: continue text = m.group(1) - text = re.sub('\s*', '', text) + text = re.sub(r'\s*', '', text) m = re.search('"wgPageName":"([^"]*)"', text) if not m: continue title = m.group(1) - target = os.path.relpath(os.path.abspath(fn), os.path.abspath(directory)) + target = os.path.relpath(os.path.abspath(fn), + os.path.abspath(directory)) link_map.add_link(title, target) return link_map + def main(): link_map = build_link_map('output/reference') - # create an xml file containing mapping between page title and actual location + # create an xml file containing mapping between page title and actual + # location link_map.write('output/link-map.xml') + if __name__ == "__main__": main() diff --git a/commands/preprocess.py b/commands/preprocess.py index 2412aa631..45682f54f 100644 --- a/commands/preprocess.py +++ b/commands/preprocess.py @@ -19,23 +19,25 @@ import fnmatch import io -from lxml import etree -import re import os -import sys +import re import shutil import urllib.parse -from xml_utils import xml_escape, xml_unescape + +from lxml import etree + def rmtree_if_exists(dir): if os.path.isdir(dir): shutil.rmtree(dir) + def move_dir_contents_to_dir(srcdir, dstdir): for fn in os.listdir(srcdir): shutil.move(os.path.join(srcdir, fn), os.path.join(dstdir, fn)) + def rearrange_archive(root): # rearrange the archive. {root} here is output/reference @@ -71,8 +73,10 @@ def rearrange_archive(root): move_dir_contents_to_dir(src_data_path, data_path) # also copy the custom fonts - shutil.copy(os.path.join(path, 'DejaVuSansMonoCondensed60.ttf'), data_path) - shutil.copy(os.path.join(path, 'DejaVuSansMonoCondensed75.ttf'), data_path) + shutil.copy(os.path.join(path, 'DejaVuSansMonoCondensed60.ttf'), + data_path) + shutil.copy(os.path.join(path, 'DejaVuSansMonoCondensed75.ttf'), + data_path) # remove what's left shutil.rmtree(path) @@ -81,79 +85,76 @@ def rearrange_archive(root): for fn in fnmatch.filter(os.listdir(root), 'cppreference-export*.xml'): os.remove(os.path.join(root, fn)) -def add_file_to_rename_map(rename_map, dir, fn, new_fn): - path = os.path.join(dir, fn) - if not os.path.isfile(path): - print("ERROR: Not renaming '{0}' because path does not exist".format(path)) - return - rename_map.append((dir, fn, new_fn)) -# Converts complex URL to resources supplied by MediaWiki loader to a simplified -# name def convert_loader_name(fn): + # Converts complex URL to resources supplied by MediaWiki loader to a + # simplified name if "modules=site&only=scripts" in fn: return "site_scripts.js" - elif "modules=site&only=styles" in fn: + if "modules=site&only=styles" in fn: return "site_modules.css" - elif "modules=startup&only=scripts" in fn: + if "modules=startup&only=scripts" in fn: return "startup_scripts.js" - elif re.search("modules=skins.*&only=scripts", fn): + if re.search("modules=skins.*&only=scripts", fn): return "skin_scripts.js" - elif re.search("modules=.*ext.*&only=styles", fn): + if re.search("modules=.*ext.*&only=styles", fn): return "ext.css" - else: - raise Exception('Loader file {0} does not match any known files'.format(fn)) + msg = 'Loader file {0} does not match any known files'.format(fn) + raise Exception(msg) + -def find_files_to_be_renamed(root): - # Returns a rename map: array of tuples each of which contain three strings: - # the directory the file resides in, the source and destination filenames. +def build_rename_map(root): + # Returns a rename map: a map from old to new file name + loader = re.compile(r'load\.php\?.*') + query = re.compile(r'\?.*') + result = dict() - # The rename map specifies files to be renamed in order to support them on - # windows filesystems which don't support certain characters in file names - rename_map = [] + # find files with invalid names -> rename all occurrences + for fn in set(fn for _, _, filenames in os.walk(root) for fn in filenames): + if loader.match(fn): + result[fn] = convert_loader_name(fn) - files_rename = [] # general files to be renamed - files_loader = [] # files served by load.php. These should map to - # consistent and short file names because we - # modify some of them later in the pipeline + elif any((c in fn) for c in '?*"'): + new_fn = query.sub('', fn) + new_fn = new_fn.replace('"', '_q_') + new_fn = new_fn.replace('*', '_star_') + result[fn] = new_fn + # find files that conflict on case-insensitive filesystems for dir, _, filenames in os.walk(root): - filenames_loader = set(fnmatch.filter(filenames, 'load.php[?]*')) - # match any filenames with '?"*' characters - filenames_rename = set(fnmatch.filter(filenames, '*[?"*]*')) - - # don't process load.php files in general rename handler - filenames_rename -= filenames_loader - - for fn in filenames_loader: - files_loader.append((dir, fn)) - for fn in filenames_rename: - files_rename.append((dir, fn)) - - for dir, orig_fn in files_rename: - fn = orig_fn - fn = re.sub(r'\?.*', '', fn) - fn = fn.replace('"', '_q_') - fn = fn.replace('*', '_star_') - add_file_to_rename_map(rename_map, dir, orig_fn, fn) - - # map loader names to more recognizable names - for dir, fn in files_loader: - new_fn = convert_loader_name(fn) - add_file_to_rename_map(rename_map, dir, fn, new_fn) - - # rename filenames that conflict on case-insensitive filesystems - # TODO: perform this automatically - add_file_to_rename_map(rename_map, os.path.join(root, 'en/cpp/numeric/math'), 'NAN.html', 'NAN.2.html') - add_file_to_rename_map(rename_map, os.path.join(root, 'en/c/numeric/math'), 'NAN.html', 'NAN.2.html') - return rename_map - -def rename_files(rename_map): - for dir, old_fn, new_fn in rename_map: + seen = dict() + for fn in (result.get(s, s) for s in filenames): + low = fn.lower() + num = seen.setdefault(low, 0) + if num > 0: + name, ext = os.path.splitext(fn) + # add file with its path -> only rename that occurrence + result[os.path.join(dir, fn)] = \ + "{}.{}{}".format(name, num + 1, ext) + seen[low] += 1 + + return result + + +def rename_files(root, rename_map): + for dir, old_fn in ((dir, fn) + for dir, _, filenames in os.walk(root) + for fn in filenames): src_path = os.path.join(dir, old_fn) - dst_path = os.path.join(dir, new_fn) - print("Renaming '{0}' to \n '{1}'".format(src_path, dst_path)) - shutil.move(src_path, dst_path) + + new_fn = rename_map.get(old_fn) + if new_fn: + # look for case conflict of the renamed file + new_path = os.path.join(dir, new_fn) + new_fn = rename_map.get(new_path, new_fn) + else: + # original filename unchanged, look for case conflict + new_fn = rename_map.get(src_path) + if new_fn: + dst_path = os.path.join(dir, new_fn) + print("Renaming {0}\n to {1}".format(src_path, dst_path)) + shutil.move(src_path, dst_path) + def find_html_files(root): # find files that need to be preprocessed @@ -163,21 +164,25 @@ def find_html_files(root): html_files.append(os.path.join(dir, filename)) return html_files + def is_loader_link(target): if re.match(r'https?://[a-z]+\.cppreference\.com/mwiki/load\.php', target): return True return False + def transform_loader_link(target, file, root): # Absolute loader.php links need to be made relative - abstarget = os.path.join(root, "common/" + convert_loader_name(target)) + abstarget = os.path.join(root, "common", convert_loader_name(target)) return os.path.relpath(abstarget, os.path.dirname(file)) + def is_ranges_placeholder(target): - if re.match(r'https?://[a-z]+\.cppreference\.com/w/cpp/ranges(-[a-z]+)?-placeholder/.+', target): + if re.match(r'https?://[a-z]+\.cppreference\.com/w/cpp/ranges(-[a-z]+)?-placeholder/.+', target): # noqa return True return False + def transform_ranges_placeholder(target, file, root): # Placeholder link replacement is implemented in the MediaWiki site JS at # https://en.cppreference.com/w/MediaWiki:Common.js @@ -186,9 +191,9 @@ def transform_ranges_placeholder(target, file, root): repl = (r'\1/cpp/experimental/ranges/\2' if ranges else r'\1/cpp/\2') if 'ranges-placeholder' in target: - match = r'https?://([a-z]+)\.cppreference\.com/w/cpp/ranges-placeholder/(.+)' + match = r'https?://([a-z]+)\.cppreference\.com/w/cpp/ranges-placeholder/(.+)' # noqa else: - match = r'https?://([a-z]+)\.cppreference\.com/w/cpp/ranges-([a-z]+)-placeholder/(.+)' + match = r'https?://([a-z]+)\.cppreference\.com/w/cpp/ranges-([a-z]+)-placeholder/(.+)' # noqa repl += (r'/\3' if ranges else r'/ranges/\3') # Turn absolute placeholder link into site-relative link @@ -198,27 +203,38 @@ def transform_ranges_placeholder(target, file, root): abstarget = os.path.join(root, reltarget) return os.path.relpath(abstarget, os.path.dirname(file)) + def is_external_link(target): - external_link_patterns = [ - 'http://', - 'https://', - 'ftp://' - ] - for pattern in external_link_patterns: - if target.startswith(pattern): - return True - return False + url = urllib.parse.urlparse(target) + return url.scheme != '' or url.netloc != '' + + +def trasform_relative_link(rename_map, target, file): + # urlparse returns (scheme, host, path, params, query, fragment) + _, _, path, params, _, fragment = urllib.parse.urlparse(target) + assert params == '' + + path = urllib.parse.unquote(path) + path = path.replace('../../upload.cppreference.com/mwiki/', '../common/') + path = path.replace('../mwiki/', '../common/') + + dir, fn = os.path.split(path) + new_fn = rename_map.get(fn) + if new_fn: + # look for case conflict of the renamed file + abstarget = os.path.normpath( + os.path.join(os.path.dirname(file), dir, new_fn)) + new_fn = rename_map.get(abstarget, new_fn) + else: + # original filename unchanged, look for case conflict + abstarget = os.path.normpath(os.path.join(os.path.dirname(file), path)) + new_fn = rename_map.get(abstarget) + if new_fn: + path = os.path.join(dir, new_fn) + + path = urllib.parse.quote(path) + return urllib.parse.urlunparse(('', '', path, params, '', fragment)) -def trasform_relative_link(rename_map, target): - target = urllib.parse.unquote(target) - for _, fn, new_fn in rename_map: - target = target.replace(fn, new_fn) - target = target.replace('../../upload.cppreference.com/mwiki/','../common/') - target = target.replace('../mwiki/','../common/') - target = re.sub(r'(\.php|\.css)\?.*', r'\1', target) - target = urllib.parse.quote(target) - target = target.replace('%23', '#') - return target # Transforms a link in the given file according to rename map. # target is the link to transform. @@ -234,7 +250,8 @@ def transform_link(rename_map, target, file, root): if is_external_link(target): return target - return trasform_relative_link(rename_map, target) + return trasform_relative_link(rename_map, target, file) + def has_class(el, *classes_to_check): value = el.get('class') @@ -246,6 +263,7 @@ def has_class(el, *classes_to_check): return True return False + # remove non-printable elements def remove_noprint(html): for el in html.xpath('//*'): @@ -254,20 +272,22 @@ def remove_noprint(html): elif el.get('id') in ['toc', 'catlinks']: el.getparent().remove(el) + # remove see also links between C and C++ documentations def remove_see_also(html): for el in html.xpath('//tr[@class]'): - if not has_class(el, 't-dcl-list-item'): + if not has_class(el, 't-dcl-list-item', 't-dsc'): continue child_tds = el.xpath('.//td/div[@class]') - if not any(has_class(td, 't-dcl-list-see') for td in child_tds): + if not any(has_class(td, 't-dcl-list-see', 't-dsc-see') + for td in child_tds): continue # remove preceding separator, if any prev = el.getprevious() if prev is not None: - child_tds = prev.xpath('.//td[@class') + child_tds = prev.xpath('.//td[@class]') if any(has_class(td, 't-dcl-list-sep') for td in child_tds): prev.getparent().remove(prev) @@ -280,65 +300,85 @@ def remove_see_also(html): next = el.getnext() if next is None: el.getparent().remove(el) - continue - - if next.tag != 'table': - continue - - if not has_class(next, 't-dcl-list-begin'): - continue - - if len(next.xpath('.//tr')) > 0: - continue + elif next.tag == 'table' and has_class(next, 't-dcl-list-begin') and \ + len(next.xpath('.//tr')) == 0: + el.getparent().remove(el) + next.getparent().remove(next) - el.getparent().remove(el) - next.getparent().remove(next) # remove Google Analytics scripts def remove_google_analytics(html): for el in html.xpath('/html/body/script'): - if el.get('src') is not None and 'google-analytics.com/ga.js' in el.get('src'): - el.getparent().remove(el) - elif el.text is not None and ('google-analytics.com/ga.js' in el.text or 'pageTracker' in el.text): - el.getparent().remove(el) + if el.get('src') is not None: + if 'google-analytics.com/ga.js' in el.get('src'): + el.getparent().remove(el) + elif el.text is not None: + if 'google-analytics.com/ga.js' in el.text or \ + 'pageTracker' in el.text: + el.getparent().remove(el) -# remove Carbon ads + +# remove ads def remove_ads(html): + # Carbon Ads for el in html.xpath('//script[@src]'): if 'carbonads.com/carbon.js' in el.get('src'): el.getparent().remove(el) for el in html.xpath('/html/body/style'): if el.text is not None and '#carbonads' in el.text: el.getparent().remove(el) + # BuySellAds + for el in html.xpath('//script[@type]'): + if 'buysellads.com' in el.text: + el.getparent().remove(el) + for el in html.xpath('//div[@id]'): + if el.get('id').startswith('bsap_'): + el.getparent().remove(el) + + +# remove links to file info pages (e.g. on images) +def remove_fileinfo(html): + info = etree.XPath(r"//a[re:test(@href, 'https?://[a-z]+\.cppreference\.com/w/File:')]/..", # noqa + namespaces={'re':'http://exslt.org/regular-expressions'}) # noqa + for el in info(html): + el.getparent().remove(el) + + +# remove external links to unused resources +def remove_unused_external(html): + for el in html.xpath('/html/head/link'): + if el.get('rel') in ('alternate', 'search', 'edit', 'EditURI'): + el.getparent().remove(el) + elif el.get('rel') == 'shortcut icon': + (head, tail) = os.path.split(el.get('href')) + el.set('href', os.path.join(head, 'common', tail)) + def preprocess_html_file(root, fn, rename_map): parser = etree.HTMLParser() html = etree.parse(fn, parser) output = io.StringIO() - # remove external links to unused resources - for el in html.xpath('/html/head/link'): - if el.get('rel') in [ 'alternate', 'search', 'edit', 'EditURI' ]: - el.getparent().remove(el) - + remove_unused_external(html) remove_noprint(html) remove_see_also(html) remove_google_analytics(html) remove_ads(html) + remove_fileinfo(html) # apply changes to links caused by file renames - for el in html.xpath('//*[@src or @href]'): - if el.get('src') is not None: - el.set('src', transform_link(rename_map, el.get('src'), fn, root)) - elif el.get('href') is not None: - el.set('href', transform_link(rename_map, el.get('href'), fn, root)) + for el in html.xpath('//*[@src]'): + el.set('src', transform_link(rename_map, el.get('src'), fn, root)) + for el in html.xpath('//*[@href]'): + el.set('href', transform_link(rename_map, el.get('href'), fn, root)) - for err in parser.error_log: + for err in list(parser.error_log): print("HTML WARN: {0}".format(err), file=output) html.write(fn, encoding='utf-8', method='html') return output.getvalue() + def preprocess_css_file(fn): f = open(fn, "r", encoding='utf-8') text = f.read() @@ -346,8 +386,13 @@ def preprocess_css_file(fn): # note that query string is not used in css files - text = text.replace('../DejaVuSansMonoCondensed60.ttf', 'DejaVuSansMonoCondensed60.ttf') - text = text.replace('../DejaVuSansMonoCondensed75.ttf', 'DejaVuSansMonoCondensed75.ttf') + text = text.replace('../DejaVuSansMonoCondensed60.ttf', + 'DejaVuSansMonoCondensed60.ttf') + text = text.replace('../DejaVuSansMonoCondensed75.ttf', + 'DejaVuSansMonoCondensed75.ttf') + + text = text.replace('../../upload.cppreference.com/mwiki/images/', + 'images/') # QT Help viewer doesn't understand nth-child text = text.replace('nth-child(1)', 'first-child') @@ -355,3 +400,13 @@ def preprocess_css_file(fn): f = open(fn, "w", encoding='utf-8') f.write(text) f.close() + + +def preprocess_startup_script(fn): + with open(fn, "r", encoding='utf-8') as f: + text = f.read() + + text = re.sub(r'document\.write\([^)]+\);', '', text) + + with open(fn, "w", encoding='utf-8') as f: + f.write(text) diff --git a/commands/preprocess_cssless.py b/commands/preprocess_cssless.py index 960ffaf30..e6f9e0220 100644 --- a/commands/preprocess_cssless.py +++ b/commands/preprocess_cssless.py @@ -15,16 +15,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. -from premailer import Premailer -import cssutils -from lxml import html -from lxml import etree -from io import StringIO -from lxml.etree import strip_elements +import copy +import functools +import io import logging import os import warnings -import io + +import cssutils +from lxml import etree +from lxml.etree import strip_elements +from premailer import Premailer + def preprocess_html_merge_cssless(src_path, dst_path): with open(src_path, 'r') as a_file: @@ -46,9 +48,11 @@ def preprocess_html_merge_cssless(src_path, dst_path): os.makedirs(head, exist_ok=True) with open(dst_path, 'wb') as a_file: - root.getroottree().write(a_file, pretty_print=True, method="html", encoding='utf-8') + root.getroottree().write(a_file, pretty_print=True, method="html", + encoding='utf-8') return output + def silence_cssutils_warnings(): log = logging.Logger('ignore') output = io.StringIO() @@ -60,6 +64,7 @@ def silence_cssutils_warnings(): return output + def preprocess_html_merge_css(root, src_path): # cssutils_logging_handler of Premailer.__init__ is insufficient to silence # warnings to stderr in non-verbose mode @@ -73,9 +78,11 @@ def preprocess_html_merge_css(root, src_path): return output.getvalue() + def strip_style_tags(root): strip_elements(root, 'style') + def needs_td_wrapper(element): # element has table:row if len(element.getchildren()) == 0: @@ -86,31 +93,62 @@ def needs_td_wrapper(element): return False return True -def remove_css_property(element, property_name): - atrib = cssutils.parseStyle(element.get('style')) - atrib.removeProperty(property_name) - element.set('style', atrib.getCssText(separator='')) - if len(element.get('style')) == 0: - element.attrib.pop('style') -def get_css_property_value(el, prop_name): - atrib = cssutils.parseStyle(el.get('style')) +@functools.lru_cache(maxsize=None) +def cssutils_parse_style_cached_nocopy(style): + return cssutils.parseStyle(style) + + +def cssutils_parse_style_cached(style): + return copy.deepcopy(cssutils_parse_style_cached_nocopy(style)) + + +@functools.lru_cache(maxsize=None) +def get_css_style_property_value(style, prop_name): + atrib = cssutils_parse_style_cached_nocopy(style) value = atrib.getPropertyCSSValue(prop_name) if value: return value.cssText return None -def has_css_property_value(el, prop_name, prop_value): - value = get_css_property_value(el, prop_name) + +@functools.lru_cache(maxsize=None) +def has_css_style_property_value(style, prop_name, prop_value): + value = get_css_style_property_value(style, prop_name) if value and value == prop_value: return True return False + +@functools.lru_cache(maxsize=None) +def remove_css_style_property(style, property_name): + atrib = cssutils_parse_style_cached(style) + atrib.removeProperty(property_name) + return atrib.getCssText(separator='') + + +def remove_css_property(element, property_name): + new_style = remove_css_style_property(element.get('style'), property_name) + if len(new_style) > 0: + element.set('style', new_style) + elif 'style' in element.attrib: + element.attrib.pop('style') + + +def get_css_property_value(el, prop_name): + return get_css_style_property_value(el.get('style'), prop_name) + + +def has_css_property_value(el, prop_name, prop_value): + return has_css_style_property_value(el.get('style'), prop_name, prop_value) + + def set_css_property_value(el, prop_name, prop_value): - atrib = cssutils.parseStyle(el.get('style')) + atrib = cssutils_parse_style_cached(el.get('style')) atrib.setProperty(prop_name, prop_value) el.set('style', atrib.getCssText(separator='')) + def convert_display_property_to_html_tag(element, element_tag, display_value): str_attrib_value = element.get('style') if str_attrib_value is None: @@ -120,12 +158,14 @@ def convert_display_property_to_html_tag(element, element_tag, display_value): remove_css_property(element, 'display') return True + def convert_span_table_to_tr_td(table_el): table_el.tag = 'table' remove_css_property(table_el, 'display') for element in table_el.getchildren(): - tag_renamed = convert_display_property_to_html_tag(element, 'tr', 'table-row') + tag_renamed = convert_display_property_to_html_tag( + element, 'tr', 'table-row') if tag_renamed: if needs_td_wrapper(element): td = etree.Element('td') @@ -137,7 +177,9 @@ def convert_span_table_to_tr_td(table_el): element.text = None else: for child in element: - convert_display_property_to_html_tag(child, 'td', 'table-cell') + convert_display_property_to_html_tag( + child, 'td', 'table-cell') + def wrap_element(el, tag_name, style): new_el = etree.Element(tag_name) @@ -145,11 +187,13 @@ def wrap_element(el, tag_name, style): el.addprevious(new_el) new_el.insert(0, el) + def remove_display_none(root_el): for el in root_el.xpath('//*[contains(@style, "display")]'): if has_css_property_value(el, 'display', 'none'): el.getparent().remove(el) + def convert_span_tables_to_tr_td(root_el): # note that the following xpath expressions match only the prefix of the # CSS property value @@ -158,11 +202,12 @@ def convert_span_tables_to_tr_td(root_el): for table_el in table_els: if has_css_property_value(table_el, 'display', 'table'): convert_span_table_to_tr_td(table_el) - #wrap_element(table_el, 'div', 'display:inline') - #convert_span_table_to_tr_td(table_el) + # wrap_element(table_el, 'div', 'display:inline') + # convert_span_table_to_tr_td(table_el) return root_el + def convert_inline_block_elements_to_table(root_el): for el in root_el.xpath('//*[contains(@style, "display")]'): if not has_css_property_value(el, 'display', 'inline-block') and \ @@ -198,6 +243,7 @@ def convert_inline_block_elements_to_table(root_el): el.getparent().remove(el) td.append(el) + def get_table_rows(table_el): for el in table_el.iterchildren(['th', 'tr']): yield el @@ -205,28 +251,33 @@ def get_table_rows(table_el): for el2 in el.iterchildren(['th', 'tr']): yield el2 + def get_max_number_of_columns(table_el): max_tds = 0 for row_el in get_table_rows(table_el): max_tds = max(max_tds, len(list(row_el.iterchildren('td')))) return max_tds + def clear_tr_border_top(tr_el): for td_el in tr_el.iterchildren('td'): remove_css_property(td_el, 'border-top') + def has_tr_border_top(tr_el): for td_el in tr_el.iterchildren('td'): if get_css_property_value(td_el, 'border-top') is not None: return True return False + def has_table_border_top(table_el): for tr_el in get_table_rows(table_el): if has_tr_border_top(tr_el): return True return False + def convert_table_border_top_to_tr_background(root_el): for table_el in root_el.iter('table'): if not has_table_border_top(table_el): @@ -244,6 +295,7 @@ def convert_table_border_top_to_tr_background(root_el): 'background-color: #ccc;') tr_el.addprevious(border_tr) + def convert_zero_td_width_to_nonzero(root_el): for el in root_el.xpath('//*[contains(@style, "width")]'): if has_css_property_value(el, 'width', '0%'): @@ -253,6 +305,7 @@ def convert_zero_td_width_to_nonzero(root_el): for el in root_el.xpath('//*[contains(@width, "0%")]'): el.attrib['width'] = "1px" + def apply_font_size(size, parent_size_pt): size = size.strip() @@ -269,8 +322,9 @@ def apply_font_size(size, parent_size_pt): return parent_size_pt + def convert_font_size_property_to_pt_recurse(el, parent_size_pt): - size_value = get_css_property_value(el,"font-size") + size_value = get_css_property_value(el, "font-size") if size_value: el_size_pt = apply_font_size(size_value, parent_size_pt) @@ -281,5 +335,6 @@ def convert_font_size_property_to_pt_recurse(el, parent_size_pt): for child in el.getchildren(): convert_font_size_property_to_pt_recurse(child, el_size_pt) + def convert_font_size_property_to_pt(root_el, default_size): - convert_font_size_property_to_pt_recurse(root_el, default_size) + convert_font_size_property_to_pt_recurse(root_el, default_size) diff --git a/config/flake8rc b/config/flake8rc new file mode 100644 index 000000000..d12aac637 --- /dev/null +++ b/config/flake8rc @@ -0,0 +1,6 @@ +[flake8] + +show-source = yes +statistics = yes +count = yes +max-line-length = 80 diff --git a/config/pylintrc b/config/pylintrc new file mode 100644 index 000000000..373c6473f --- /dev/null +++ b/config/pylintrc @@ -0,0 +1,392 @@ +[MASTER] + +# Profiled execution. +profile=no + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore= + +# Pickle collected data for later comparisons. +persistent=no + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + + +[MESSAGES CONTROL] + +# For now disable bunch of checks that does not pass. Some of them should be +# re-enabled and reported issues fixed, while most are bugs in pylint and could +# be re-enabled when those are fixed. + +# Following are the checks we don't care about, and thus should remain disabled +# +# blacklisted-name +# missing-docstring +# too-many-lines +# no-self-use +# duplicate-code +# too-many-ancestors +# too-many-instance-attributes +# too-few-public-methods +# too-many-public-methods +# too-many-return-statements +# too-many-branches +# too-many-arguments +# too-many-locals +# too-many-statements +# abstract-class-not-used +# abstract-class-little-used +# exec-used +# star-args +# deprecated-module +# fixme +# global-variable-undefined +# unused-argument +# unpacking-non-sequence +# maybe-no-member + +# "bad-continuation" disabled due to conflict with flake8 (and PEP8) +# See +# flake8 wants: +# func("..." +# ) +# pylint wants: +# func("..." +# ) + +disable= + blacklisted-name, + invalid-name, + missing-docstring, + too-many-lines, + no-self-use, + chained-comparison, + duplicate-code, + too-many-ancestors, + too-many-instance-attributes, + too-few-public-methods, + too-many-public-methods, + too-many-return-statements, + too-many-branches, + too-many-arguments, + too-many-locals, + too-many-statements, + abstract-class-not-used, + abstract-class-little-used, + deprecated-module, + fixme, + global-variable-undefined, + unused-argument, + maybe-no-member, + locally-disabled, + bad-classmethod-argument, + line-too-long, + old-style-class, + method-hidden, + no-name-in-module, + no-member, + not-callable, + too-many-function-args, + unexpected-keyword-arg, + redundant-keyword-arg, + import-error, + cyclic-import, + exec-used, + star-args, + unreachable, + dangerous-default-value, + pointless-statement, + pointless-string-statement, + expression-not-assigned, + unnecessary-pass, + unnecessary-lambda, + deprecated-lambda, + useless-else-on-loop, + bad-builtin, + attribute-defined-outside-init, + protected-access, + arguments-differ, + signature-differs, + abstract-method, + super-init-not-called, + no-init, + non-parent-init-called, + bad-indentation, + relative-import, + global-statement, + unused-variable, + redefined-outer-name, + redefined-builtin, + redefined-variable-type, + unidiomatic-typecheck, + undefined-loop-variable, + unbalanced-tuple-unpacking, + unpacking-non-sequence, + raising-string, + broad-except, + nonstandard-exception, + anomalous-unicode-escape-in-string, + bad-open-mode, + superfluous-parens, + no-self-argument, + no-value-for-parameter, + interface-not-implemented, + bad-continuation, + keyword-arg-before-vararg, + unsubscriptable-object, + inconsistent-return-statements, # (implicit return None) + len-as-condition, + too-many-boolean-expressions, + useless-object-inheritance + +[REPORTS] + +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html. You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Change the default error message template. +msg-template={path}:{line}:{column}: error: {msg} [{symbol}] + +# Include message's id in output +include-ids=yes + +# Include symbolic ids of messages in output +symbols=yes + +# Put messages in a separate file for each module / package specified on the +# command line instead of printing them on stdout. Reports (if any) will be +# written in a file name "pylint_global.[txt|html]". +files-output=no + +# Tells whether to display a full report or only the messages +reports=no + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Add a comment according to your evaluation note. This is used by the global +# evaluation report (RP0004). +comment=no + + +[SPELLING] + +# Spelling dictionary name. +# If this value will be non-empty (e.g. 'en_US') and pyenchant will not be +# installed, pylint will fail. +# If this will be left empty pylint will ignore all spelling errors. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +# Path relative to current working directory. +spelling-private-dict-file=../common/code_spelling_ignore_words.txt + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + + +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=80 + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + + +[TYPECHECK] + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of classes names for which member attributes should not be checked +# (useful for classes with attributes dynamically set). +ignored-classes=SQLObject + +# When zope mode is activated, add a predefined set of Zope acquired attributes +# to generated-members. +zope=no + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E0201 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST,acl_users,aq_parent + + +[BASIC] + +# Will be removed in PyLint 2.0 +# Required attributes for module, separated by a comma +#required-attributes= + +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,filter,apply,input + +# Regular expression which should only match correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression which should only match correct module level names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression which should only match correct class names +class-rgx=[A-Z_][a-zA-Z0-9_]+$ + +# Regular expression which should only match correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct method names +method-rgx=[_]{0,2}[a-z_][a-z0-9_]{2,30}[_]{0,2}$ + +# Regular expression which should only match correct instance attribute names +attr-rgx=[a-z_][a-z0-9]{2,30}$ + +# Regular expression which should only match correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct list comprehension / +# generator expression variable names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names= + +# Regular expression which should only match functions or classes name which do +# not require a docstring +no-docstring-rgx=__.*__ + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the beginning of the name of dummy variables +# (i.e. not used). +dummy-variables-rgx=_|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + + +[CLASSES] + +# This option will be removed in PyLint 2.0. +# List of interface methods to ignore, separated by a comma. This is used for +# instance to not check methods defines in Zope's Interface base class. +# ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[IMPORTS] + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branchs=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception + +extension-pkg-whitelist=lxml diff --git a/ddg_parse_html.py b/ddg_parse_html.py index 12d8ab79e..7e30df69d 100644 --- a/ddg_parse_html.py +++ b/ddg_parse_html.py @@ -1,4 +1,4 @@ - #!/usr/bin/env python3 +#!/usr/bin/env python3 ''' Copyright (C) 2013 Povilas Kanapickas @@ -18,23 +18,26 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -import lxml.etree as e import re from copy import deepcopy +import lxml.etree as e + + class DdgException(Exception): pass -''' Returns the element in which the content is stored. -''' + def get_content_el(root_el): + # Returns the element in which the content is stored. try: return root_el.xpath('''/html/body/div[@id="cpp-content-base"] /div[@id="content"] /div[@id="bodyContent"] /div[@class="mw-content-ltr"]''')[0] - except: - raise DdgException("Could not find content element") + except Exception as e: + raise DdgException("Could not find content element") from e + VERSION_C89 = 0 VERSION_C99 = 1 @@ -44,18 +47,20 @@ def get_content_el(root_el): VERSION_CXX11 = 102 VERSION_CXX14 = 103 -''' Returns the declaration of the feature with name 'name'. - If several declarations with the same name are present, and entries - superseded in the later standards (as determined by the presence of until - XXX marker) are ignored. The rest of declarations are returned as a list of - tuples, each of which the two elements: - 1) the code of the declaration - 2) the version as defined by the 'num' dcl template parameter, or None - if no version was specified. - If no declaration is found, an exception of type DdgException is raised -''' def get_declarations(root_el, name): + ''' Returns the declaration of the feature with name 'name'. + If several declarations with the same name are present, and entries + superseded in the later standards (as determined by the presence of + until XXX marker) are ignored. The rest of declarations are returned + as a list of tuples, each of which the two elements: + 1) the code of the declaration + 2) the version as defined by the 'num' dcl template parameter, or + None if no version was specified. + + If no declaration is found, an exception of type DdgException is raised + ''' + content_el = get_content_el(root_el) dcl_tables = content_el.xpath('table[contains(@class, "t-dcl-begin")]') @@ -77,12 +82,12 @@ def get_declarations(root_el, name): # skip entries that don't contain name if re.search('[^a-zA-Z0-9_]' + re.escape(name) + '[^a-zA-Z0-9_]', - code) == None: + code) is None: ignored = True continue # skip deleted functions - if re.search('=\s*delete\s*;', code) != None: + if re.search(r'=\s*delete\s*;', code) is not None: ignored = True continue @@ -97,9 +102,9 @@ def get_declarations(root_el, name): version = None try: version_str = dcl.xpath('td[2]')[0].text_content() - version_str = re.search('\((\d*)\)', version_str).group(1) + version_str = re.search(r'\((\d*)\)', version_str).group(1) version = int(version_str) - except: + except Exception: pass dcls.append((code, version)) @@ -107,15 +112,16 @@ def get_declarations(root_el, name): if len(dcls) == 0: if not ignored: raise DdgException("dcl table contains no declarations") - else: - raise DdgException("All entries in dcl table were ignored") + raise DdgException("All entries in dcl table were ignored") return dcls + def del_all_attrs(el): for key in el.attrib: del el.attrib[key] + def iterate_top_text(text, on_text=None): last_close = 0 open_count = 0 @@ -134,6 +140,7 @@ def iterate_top_text(text, on_text=None): if open_count == 0: on_text(last_close, text[last_close:]) + def remove_parentheses(desc, max_paren_text_size): open_paren_count = 0 @@ -143,7 +150,7 @@ def remove_parentheses(desc, max_paren_text_size): def on_text(pos, text): nonlocal open_paren_count, last_paren_open, del_ranges - for match in re.finditer('(\(|\))', text): + for match in re.finditer(r'(\(|\))', text): gr = match.group(1) if gr == '(': if open_paren_count == 0: @@ -162,10 +169,11 @@ def on_text(pos, text): del_ranges.append((last_paren_open, end)) for r in reversed(del_ranges): - begin,end = r + begin, end = r desc = desc[:begin] + desc[end:] return desc + def split_sentences(desc): sentences = [] @@ -187,9 +195,11 @@ def on_text(pos, text): return sentences + def remove_punctuation_at_end(sentence): return sentence.rstrip(' .,:;') + def trim_single_sentence_at_word(sentence, max_chars): last_valid_chunk = None @@ -217,6 +227,7 @@ def on_text(pos, text): return sentence[:last_valid_chunk_pos] + last_valid_chunk + def trim_single_sentence(text, max_chars): if len(text) <= max_chars: return text @@ -225,7 +236,7 @@ def trim_single_sentence(text, max_chars): # if present. Otherwise, cut desc in the middle of the sentence, preferably # at the end of a word - #find the first match + # find the first match ie_pos = None def on_ie_text(pos, match_text): @@ -250,21 +261,23 @@ def on_ie_text(pos, match_text): text = trim_single_sentence_at_word(text, max_chars) return remove_punctuation_at_end(text) + '...' -''' Processes description text. Drops all tags except and . Replaces - with . Replaces span.mw-geshi with . Returns the processed - description as str. - - The description is limited to max_sentences number of sentences and - max_chars number of characters (each delimited by a dot). - If a single sentence is longer than max_chars characters, '...' is appended. - Setting max_paren_text_size to controls the maximum number of characters in - parenthesized text. If the size of parenthesized block exceeds that, it is - removed. Such blocks within , or tag are ignored. -''' def process_description(el, max_sentences, max_chars, max_paren_text_size, debug=False): - + ''' Processes description text. Drops all tags except and . + Replaces with . Replaces span.mw-geshi with . Returns the + processed description as str. + + The description is limited to max_sentences number of sentences and + max_chars number of characters (each delimited by a dot). + If a single sentence is longer than max_chars characters, '...' is + appended. + + Setting max_paren_text_size to controls the maximum number of + characters in parenthesized text. If the size of parenthesized block + exceeds that, it is removed. Such blocks within , or tag + are ignored. + ''' el = deepcopy(el) # we'll modify the tree el.tag = 'root' del_all_attrs(el) @@ -278,12 +291,12 @@ def process_description(el, max_sentences, max_chars, else: t.drop_tag() desc = e.tostring(el, method='html', encoding=str, with_tail=False) - desc = desc.replace('','').replace('','') + desc = desc.replace('', '').replace('', '') if debug: print("ROOT: " + desc) # description must never contain newlines - desc = desc.replace('\n',' ') + desc = desc.replace('\n', ' ') # Handle 'i.e.' and 'that is' as a special case desc = desc.replace('i.e.', 'ᚃ') @@ -293,9 +306,6 @@ def process_description(el, max_sentences, max_chars, # remove text in parentheses (except when it's within some tag) # get the position of the cut of the description - open_count = 0 - open_paren_count = 0 - desc = remove_parentheses(desc, max_paren_text_size) sentences = split_sentences(desc) @@ -326,38 +336,38 @@ def process_description(el, max_sentences, max_chars, return desc -''' Returns a short description of a feature. This is the first sentence after - the declaration (dcl template). If a list follows immediately, then the - description is picked from a list item identified by num - Raises DdgException on error -''' def get_short_description(root_el, num, max_sentences=1, max_chars=200, max_paren_text_size=40, debug=False): + ''' Returns a short description of a feature. This is the first sentence + after the declaration (dcl template). If a list follows immediately, + then the description is picked from a list item identified by num + Raises DdgException on error + ''' content_el = get_content_el(root_el) dcl_tables = content_el.xpath('table[@class="t-dcl-begin"]') if len(dcl_tables) == 0: raise DdgException("No dcl table found") - #todo debug + # todo debug dcl_table = dcl_tables[0] desc_el = dcl_table.getnext() - if desc_el == None: + if desc_el is None: raise DdgException("No elements after dcl table") if desc_el.tag == 'p': return process_description(desc_el, max_sentences, max_chars, max_paren_text_size, debug=debug) - elif desc_el.tag == 'div' and desc_el.get('class') == 't-li1': - if num == None: + if desc_el.tag == 'div' and desc_el.get('class') == 't-li1': + if num is None: raise DdgException("Versioned summary with no version supplied") - while (desc_el != None and desc_el.tag == 'div' and - desc_el.get('class') == 't-li1'): + while (desc_el is not None and desc_el.tag == 'div' and + desc_el.get('class') == 't-li1'): index_els = desc_el.xpath('span[@class="t-li"]') if len(index_els) == 0: desc_el = desc_el.getnext() @@ -366,19 +376,19 @@ def get_short_description(root_el, num, max_sentences=1, max_chars=200, index = e.tostring(index_el, encoding=str, method='text', with_tail=False) - m = re.match('^\s*(\d+)\)\s*$', index) + m = re.match(r'^\s*(\d+)\)\s*$', index) if m and int(m.group(1)) == num: index_el.drop_tree() return process_description(desc_el, max_sentences, max_chars, max_paren_text_size, debug=debug) - m = re.match('^\s*(\d+)-(\d+)\)\s*$', index) + m = re.match(r'^\s*(\d+)-(\d+)\)\s*$', index) if m and int(m.group(1)) <= num and int(m.group(2)) >= num: index_el.drop_tree() return process_description(desc_el, max_sentences, max_chars, max_paren_text_size, debug=debug) - m = re.match('^\s*(\d+),(\d+)\)\s*$', index) + m = re.match(r'^\s*(\d+),(\d+)\)\s*$', index) if m and num in [int(m.group(1)), int(m.group(2))]: index_el.drop_tree() return process_description(desc_el, max_sentences, max_chars, diff --git a/devhelp2qch.py b/devhelp2qch.py index d6b8da475..44904c82a 100755 --- a/devhelp2qch.py +++ b/devhelp2qch.py @@ -17,21 +17,24 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. -# devhelp2qch.py script converts 'in_root' xml source file to 'out_root' xml output -# including files list from library 'files_root' at the end. -from lxml import etree -from copy import deepcopy -import sys import argparse + +from lxml import etree + from index_transform.devhelp_qch import convert_devhelp_to_qch + def main(): parser = argparse.ArgumentParser(prog='devhelp2qch.py') - parser.add_argument('--src', type=str, help='The path to the XML input file') - parser.add_argument('--dst', type=str, help='The path to the destination XML file') - parser.add_argument('--virtual_folder', type=str, help='Virtual folder name') - parser.add_argument('--file_list', type=str, help='The path to the file list in XML file') + parser.add_argument('--src', type=str, + help='The path to the XML input file') + parser.add_argument('--dst', type=str, + help='The path to the destination XML file') + parser.add_argument('--virtual_folder', type=str, + help='Virtual folder name') + parser.add_argument('--file_list', type=str, + help='The path to the file list in XML file') args = parser.parse_args() src_path = args.src @@ -44,8 +47,10 @@ def main(): file_tree = etree.parse(file_path, parser) out_f = open(dst_path, 'wb') - out_f.write(convert_devhelp_to_qch(in_tree.getroot(), file_tree.getroot(), v_folder)) + out_f.write(convert_devhelp_to_qch(in_tree.getroot(), file_tree.getroot(), + v_folder)) out_f.close() + if __name__ == "__main__": main() diff --git a/export.py b/export.py index bc449bce7..b4d5b4241 100755 --- a/export.py +++ b/export.py @@ -19,9 +19,10 @@ ''' import argparse +import json import urllib.parse import urllib.request -import json + def retrieve_page_names(root, ns_index): @@ -30,11 +31,11 @@ def retrieve_page_names(root, ns_index): while True: params = { - 'action' : 'query', - 'list' : 'allpages', - 'apnamespace' : ns_index, - 'aplimit' : 500, - 'format' : 'json' + 'action': 'query', + 'list': 'allpages', + 'apnamespace': ns_index, + 'aplimit': 500, + 'format': 'json' } if begin is not None: params['apcontinue'] = begin @@ -43,19 +44,21 @@ def retrieve_page_names(root, ns_index): with urllib.request.urlopen(url) as f: data = json.loads(f.read().decode('utf-8')) - pages += [ p['title'] for p in data['query']['allpages'] ] + pages += [p['title'] for p in data['query']['allpages']] - if ('query-continue' in data and 'allpages' in data['query-continue'] and - 'apcontinue' in data['query-continue']['allpages']): + if ('query-continue' in data and + 'allpages' in data['query-continue'] and + 'apcontinue' in data['query-continue']['allpages']): begin = data['query-continue']['allpages']['apcontinue'] else: return pages + def export_pages(root, pages, output_path): params = { - 'wpDownload' : '', - 'curonly' : 1, - 'pages' : '\n'.join(pages) + 'wpDownload': '', + 'curonly': 1, + 'pages': '\n'.join(pages) } data = urllib.parse.urlencode(params) @@ -64,21 +67,28 @@ def export_pages(root, pages, output_path): urllib.request.urlretrieve(url, output_path, data=data) + def main(): parser = argparse.ArgumentParser(prog='export.py') - parser.add_argument('--url', type=str, help='The URL to the root of the MediaWiki installation') - parser.add_argument('output_path', type=str, help='The path to the XML file to save output to') - parser.add_argument('ns_index', type=str, nargs='+', help='The indices of the namespaces to retrieve') + parser.add_argument('--url', type=str, + help='The URL to the root of the MediaWiki ' + 'installation') + parser.add_argument('output_path', type=str, + help='The path to the XML file to save output to') + parser.add_argument('ns_index', type=str, nargs='+', + help='The indices of the namespaces to retrieve') args = parser.parse_args() pages = [] for ns_index in args.ns_index: new_pages = retrieve_page_names(args.url, ns_index) - print("Retrieved {0} pages for namespace {1}".format(len(new_pages), ns_index)) + print("Retrieved {0} pages for namespace {1}".format(len(new_pages), + ns_index)) pages += new_pages pages = sorted(pages) export_pages(args.url, pages, args.output_path) + if __name__ == "__main__": main() diff --git a/fix_devhelp-links.py b/fix_devhelp-links.py index 10c555f19..87e71c73e 100755 --- a/fix_devhelp-links.py +++ b/fix_devhelp-links.py @@ -18,9 +18,11 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' +import sys + import lxml.etree as e + from link_map import LinkMap -import sys if len(sys.argv) != 3: print('''Please provide the following 2 argument: @@ -40,7 +42,7 @@ for el in el_mod: link = el.get('link') target = mapping.get_dest(link) - if target == None: + if target is None: print('Could not find ' + link + ' in mapping') target = '404' el.set('link', target) @@ -49,4 +51,3 @@ out_f.write(e.tostring(root, encoding='utf-8', pretty_print=True, xml_declaration=True)) out_f.close() - diff --git a/gadgets/replace_tests_base.py b/gadgets/replace_tests_base.py index f7322eeb6..353d927b1 100755 --- a/gadgets/replace_tests_base.py +++ b/gadgets/replace_tests_base.py @@ -24,6 +24,7 @@ import re import sys + def get_html_files(root): files = [] for dir, dirnames, filenames in os.walk(root): diff --git a/gadgets/standard_revisions-tests/README b/gadgets/standard_revisions_tests/README similarity index 100% rename from gadgets/standard_revisions-tests/README rename to gadgets/standard_revisions_tests/README diff --git a/gadgets/standard_revisions-tests/base.py b/gadgets/standard_revisions_tests/base.py similarity index 91% rename from gadgets/standard_revisions-tests/base.py rename to gadgets/standard_revisions_tests/base.py index 848d43188..8b1269c84 100644 --- a/gadgets/standard_revisions-tests/base.py +++ b/gadgets/standard_revisions_tests/base.py @@ -17,13 +17,11 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' +import unittest + from selenium import webdriver -from selenium.webdriver.common.by import By -from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select -from selenium.common.exceptions import NoSuchElementException -from selenium.common.exceptions import NoAlertPresentException -import unittest, time, re + class Driver: def __init__(self): @@ -31,8 +29,8 @@ def __init__(self): driver = webdriver.Firefox() driver.implicitly_wait(30) try: - driver.get(base_url + "/mwiki/index.php?title=Special:UserLogout&returnto=Main+Page") - driver.get(base_url + "/mwiki/index.php?title=Special:UserLogin&returnto=Main+Page") + driver.get(base_url + "/mwiki/index.php?title=Special:UserLogout&returnto=Main+Page") # noqa + driver.get(base_url + "/mwiki/index.php?title=Special:UserLogin&returnto=Main+Page") # noqa driver.find_element_by_id("wpName1").clear() driver.find_element_by_id("wpName1").send_keys("test5") driver.find_element_by_id("wpPassword1").clear() @@ -40,18 +38,19 @@ def __init__(self): driver.find_element_by_id("wpLoginAttempt").click() if driver.find_element_by_link_text("Test5").text != "Test5": raise Exception("Could not login") - except: + except Exception: driver.quit() raise self.driver = driver self.base_url = base_url - def __del__(self): self.driver.quit() + driver_instance = Driver() + class CppTestCase(unittest.TestCase): @classmethod def setUpClass(self): diff --git a/gadgets/standard_revisions-tests/test.sh b/gadgets/standard_revisions_tests/test.sh similarity index 100% rename from gadgets/standard_revisions-tests/test.sh rename to gadgets/standard_revisions_tests/test.sh diff --git a/gadgets/standard_revisions-tests/test_dcl.py b/gadgets/standard_revisions_tests/test_dcl.py similarity index 99% rename from gadgets/standard_revisions-tests/test_dcl.py rename to gadgets/standard_revisions_tests/test_dcl.py index effeedd9c..aa7f9c7f3 100644 --- a/gadgets/standard_revisions-tests/test_dcl.py +++ b/gadgets/standard_revisions_tests/test_dcl.py @@ -17,7 +17,8 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from base import * +from base import CppTestCase + class TestDcl(CppTestCase): def test_hides_dcl_items_in_dcl_rev(self): diff --git a/gadgets/standard_revisions-tests/test_dsc.py b/gadgets/standard_revisions_tests/test_dsc.py similarity index 97% rename from gadgets/standard_revisions-tests/test_dsc.py rename to gadgets/standard_revisions_tests/test_dsc.py index 314182ba3..8ca30d99c 100644 --- a/gadgets/standard_revisions-tests/test_dsc.py +++ b/gadgets/standard_revisions_tests/test_dsc.py @@ -17,7 +17,8 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from base import * +from base import CppTestCase + class TestDsc(CppTestCase): def test_hides_dsc_items_with_explicit_mark(self): @@ -32,4 +33,3 @@ def test_hides_dsc_items_with_explicit_mark(self): self.select_cxx11() self.assert_text_in_body("std::not_visible_in_cxx98") self.assert_text_not_in_body("std::not_visible_in_cxx11") - diff --git a/gadgets/standard_revisions-tests/test_rev.py b/gadgets/standard_revisions_tests/test_rev.py similarity index 99% rename from gadgets/standard_revisions-tests/test_rev.py rename to gadgets/standard_revisions_tests/test_rev.py index 8287b51be..e522571a5 100644 --- a/gadgets/standard_revisions-tests/test_rev.py +++ b/gadgets/standard_revisions_tests/test_rev.py @@ -17,8 +17,8 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -import unittest, time, re -from base import * +from base import CppTestCase + class TestRev(CppTestCase): def test_revlist_works_in_dsc_item(self): @@ -48,7 +48,6 @@ def test_rev_inl_works_in_text(self): self.assert_text_not_in_body("not_visible_in_cxx11") def test_rev_works_with_fully_closed_ranges(self): - driver = self.driver self.get_page("test-gadget-stdrev/rev-works-with-fully-closed-ranges") self.assert_text_in_body("since-cxx03-until-none") self.assert_text_in_body("since-cxx11-until-none") diff --git a/gadgets/standard_revisions-tests/test_section_hierarchy.py b/gadgets/standard_revisions_tests/test_section_hierarchy.py similarity index 74% rename from gadgets/standard_revisions-tests/test_section_hierarchy.py rename to gadgets/standard_revisions_tests/test_section_hierarchy.py index ae246c314..a88ee01cf 100644 --- a/gadgets/standard_revisions-tests/test_section_hierarchy.py +++ b/gadgets/standard_revisions_tests/test_section_hierarchy.py @@ -16,69 +16,70 @@ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. ''' +# noqa + +from base import CppTestCase -import unittest, time, re -from base import * class TestSectionHierarchy(CppTestCase): def test_hides_h3_when_section_contains_dsc_with_removed_elems(self): driver = self.driver - self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-elems") - self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed()) + self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-elems") # noqa + self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed()) # noqa self.select_cxx98() - self.assertFalse(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed()) + self.assertFalse(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed()) # noqa self.select_cxx11() - self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed()) + self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed()) # noqa def test_hides_h3_when_section_contains_dsc_with_removed_until(self): driver = self.driver - self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-until") - self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed()) + self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-until") # noqa + self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed()) # noqa self.select_cxx98() - self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed()) + self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed()) # noqa self.select_cxx11() - self.assertFalse(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed()) + self.assertFalse(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed()) # noqa def test_hides_h3_when_section_contains_only_stdrev(self): driver = self.driver - self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-only-stdrev") - self.assertTrue(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed()) + self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-only-stdrev") # noqa + self.assertTrue(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed()) # noqa self.select_cxx98() - self.assertFalse(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed()) + self.assertFalse(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed()) # noqa self.select_cxx11() - self.assertTrue(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed()) + self.assertTrue(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed()) # noqa def test_preserves_h3_when_section_visible(self): driver = self.driver - self.get_page("test-gadget-stdrev/preserves-h3-when-section-with-h5-visible") - self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) + self.get_page("test-gadget-stdrev/preserves-h3-when-section-with-h5-visible") # noqa + self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) # noqa self.select_cxx98() - self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) + self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) # noqa self.select_cxx11() - self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) + self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) # noqa def test_preserves_h3_when_section_with_h5_visible(self): driver = self.driver - self.get_page("test-gadget-stdrev/preserves-h3-when-section-with-h5-visible") - self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) - self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed()) - self.assertTrue(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed()) + self.get_page("test-gadget-stdrev/preserves-h3-when-section-with-h5-visible") # noqa + self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) # noqa + self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed()) # noqa + self.assertTrue(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed()) # noqa self.select_cxx98() - self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) - self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed()) - self.assertFalse(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed()) + self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) # noqa + self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed()) # noqa + self.assertFalse(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed()) # noqa self.select_cxx11() - self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) - self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed()) - self.assertTrue(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed()) + self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed()) # noqa + self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed()) # noqa + self.assertTrue(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed()) # noqa diff --git a/gadgets/sync_tests_mwiki.py b/gadgets/sync_tests_mwiki.py index 9aa3fc70b..b9e13374b 100755 --- a/gadgets/sync_tests_mwiki.py +++ b/gadgets/sync_tests_mwiki.py @@ -29,17 +29,17 @@ # command line. os.environ['PYWIKIBOT2_NO_USER_CONFIG']='1' -import pywikibot -import pywikibot.config2 -import pywikibot.pagegenerators -import pywikibot.data.api - import argparse import itertools import shutil import sys import urllib +import pywikibot +import pywikibot.config2 +import pywikibot.data.api +import pywikibot.pagegenerators + SYNC_DIRECTION_UPLOAD = 1 SYNC_DIRECTION_DOWNLOAD = 2 diff --git a/headers/README.md b/headers/README.md index b3de6dfa2..e44dd4452 100644 --- a/headers/README.md +++ b/headers/README.md @@ -1,50 +1,56 @@ Information ----------- - + This directory contains dummy C++ standard library that contains only the declarations of the C++ standard library interface, to be used as an aid in code completion. -Real standard library implementations often use complex C++ techniques in order -to provide full compliance and perform optimizations. This leads to code -completion implementations being unable to resolve typedef result and function -return types, and thus being unable to provide code completion of class members -when given instance variable. This issue becomes more and more important with +Real standard library implementations often use complex C++ techniques in order +to provide full compliance and perform optimizations. This leads to code +completion implementations being unable to resolve typedef result and function +return types, and thus being unable to provide code completion of class members +when given instance variable. This issue becomes more and more important with widespread use of C++ 'auto' type specifier, because code completion of members of such variables depend on function return types being correctly resolved. This dummy library performs various steps to simplify the exposed interface, to make code completion more useful. In addition to that, descriptive parameter names are exposed instead of uglified identifiers used in real standard library -implementations. The parameter names correspond to those provided for +implementations. The parameter names correspond to those provided for respective functions in the cppreference.com C++ reference. +To simplify, noexcept specifiers are omitted from declarations. + Configuration ------------- -The exposed interface depends on the values of the following preprocessor +The exposed interface depends on the values of the following preprocessor macros: - CPPREFERENCE_STDVER: defines the standard version of the interface. Possible values are 1998, 2003, 2011, 2014, 2017 which correspond to the respective C++ standards. - - - CPPREFERENCE_SIMPLIFY_TYPEDEFS: non-zero value results in simplified - typedefs being exposed. Usage of various traits is greatly reduced; the - typedefs refer to types that would be resolved in most common cases. + + - CPPREFERENCE_INT_TYPES_ONLY_IN_STD: non-zero value results in integer types + such as std::size_t, std::uint16_t and so on being defined only in std + namespace. + + - CPPREFERENCE_SIMPLIFY_TYPEDEFS: non-zero value results in simplified + typedefs being exposed. Usage of various traits is greatly reduced; the + typedefs refer to types that would be resolved in most common cases. Enabling this is recommended. Usage ----- -The primary target for this dummy C++ standard library is the Qt Creator IDE, +The primary target for this dummy C++ standard library is the Qt Creator IDE, though the code might be useful in other IDEs. -For each Qt Creator project, perform the following steps to replace the +For each Qt Creator project, perform the following steps to replace the C++ library used by code completion: - Add the path to this directory to the $PROJECT.includes file - Define CPPREFERENCE_STDVER and/or CPPREFERENCE_SIMPLIFY_TYPEDEFS to correct - values in the $PROJECT.config file. \ No newline at end of file + values in the $PROJECT.config file. diff --git a/headers/algorithm b/headers/algorithm index 596f60ce9..86a1ef42d 100644 --- a/headers/algorithm +++ b/headers/algorithm @@ -19,6 +19,7 @@ #include #endif #include // for std::pair +#include // for std::iterator_traits namespace std { @@ -33,379 +34,446 @@ template bool none_of(InputIt first, InputIt last, UnaryPredicate p); #endif -template +template UnaryFunction for_each(InputIt first, InputIt last, UnaryFunction f); -template +template typename iterator_traits::difference_type -count(InputIt first, InputIt last, const T& value); + count(InputIt first, InputIt last, const T& value); -template +template typename iterator_traits::difference_type -count_if(InputIt first, InputIt last, UnaryPredicate p); + count_if(InputIt first, InputIt last, UnaryPredicate p); + +#if CPPREFERENCE_STDVER >= 2020 +template +std::pair +constexpr mismatch(InputIt1 first1, InputIt1 last1, + InputIt2 first2); + +template +std::pair +constexpr mismatch(InputIt1 first1, InputIt1 last1, + InputIt2 first2, + BinaryPredicate p); +#else +template +std::pair + mismatch(InputIt1 first1, InputIt1 last1, + InputIt2 first2); + +template +std::pair + mismatch(InputIt1 first1, InputIt1 last1, + InputIt2 first2, + BinaryPredicate p); +#endif -template +#if CPPREFERENCE_STDVER >= 2017 +template std::pair -mismatch(InputIt1 first1, InputIt1 last1, - InputIt2 first2); + mismatch(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2); -template +template std::pair -mismatch(InputIt1 first1, InputIt1 last1, - InputIt2 first2, - BinaryPredicate p); + mismatch(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2, + BinaryPredicate p); +#endif #if CPPREFERENCE_STDVER >= 2014 -template +template +std::pair + mismatch(InputIt1 first1, InputIt1 last1, + InputIt2 first2, InputIt2 last2); + +template +std::pair + mismatch(InputIt1 first1, InputIt1 last1, + InputIt2 first2, InputIt2 last2, + BinaryPredicate p); +#endif + +#if CPPREFERENCE_STDVER >= 2017 +template std::pair -mismatch(InputIt1 first1, InputIt1 last1, - InputIt2 first2, InputIt2 last2); + mismatch(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2, InputIt2 last2); -template +template std::pair -mismatch(InputIt1 first1, InputIt1 last1, - InputIt2 first2, InputIt2 last2, - BinaryPredicate p); + mismatch(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2, InputIt2 last2, + BinaryPredicate p); #endif -template + +template bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2); -template +template bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p); #if CPPREFERENCE_STDVER >= 2014 -template +template bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2); -template +template bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate p); #endif -template +#if CPPREFERENCE_STDVER >= 2017 +template +bool equal(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2); + +template +bool equal(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2, BinaryPredicate p); + +template +bool equal(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2, InputIt2 last2); + +template +bool equal(ExecutionPolicy&& policy, + InputIt1 first1, InputIt1 last1, + InputIt2 first2, InputIt2 last2, + BinaryPredicate p); +#endif + +template InputIt find(InputIt first, InputIt last, const T& value); -template +template InputIt find_if(InputIt first, InputIt last, UnaryPredicate p); #if CPPREFERENCE_STDVER >= 2011 -template +template InputIt find_if_not(InputIt first, InputIt last, UnaryPredicate q); #endif -template +template ForwardIt1 find_end(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last); -template +template ForwardIt1 find_end(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last, BinaryPredicate p); #if CPPREFERENCE_STDVER >= 2011 -template +template InputIt find_first_of(InputIt first, InputIt last, ForwardIt s_first, ForwardIt s_last); -template +template InputIt find_first_of(InputIt first, InputIt last, ForwardIt s_first, ForwardIt s_last, BinaryPredicate p); #else -template +template ForwardIt1 find_first_of(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last); -template +template ForwardIt1 find_first_of(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last, BinaryPredicate p); #endif -template +template ForwardIt adjacent_find(ForwardIt first, ForwardIt last); template ForwardIt adjacent_find(ForwardIt first, ForwardIt last, BinaryPredicate p); -template +template ForwardIt1 search(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last); -template +template ForwardIt1 search(ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, ForwardIt2 s_last, BinaryPredicate p); -template +template ForwardIt search_n(ForwardIt first, ForwardIt last, Size count, const T& value); -template +template ForwardIt search_n(ForwardIt first, ForwardIt last, Size count, const T& value, BinaryPredicate p); -template +template OutputIt copy(InputIt first, InputIt last, OutputIt d_first); #if CPPREFERENCE_STDVER >= 2011 -template +template OutputIt copy_if(InputIt first, InputIt last, OutputIt d_first, UnaryPredicate pred); #endif #if CPPREFERENCE_STDVER >= 2011 -template +template OutputIt copy_n(InputIt first, Size count, OutputIt result); #endif -template +template BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last); #if CPPREFERENCE_STDVER >= 2011 -template +template OutputIt move(InputIt first, InputIt last, OutputIt d_first); #endif #if CPPREFERENCE_STDVER >= 2011 -template +template OutputIt move(InputIt first, InputIt last, OutputIt d_first); #endif -template +template void fill(ForwardIt first, ForwardIt last, const T& value); #if CPPREFERENCE_STDVER >= 2011 -template +template OutputIt fill_n(OutputIt first, Size count, const T& value); #else -template +template void fill_n(OutputIt first, Size count, const T& value); #endif -template +template OutputIt transform(InputIt first1, InputIt last1, OutputIt d_first, UnaryOperation unary_op); -template +template OutputIt transform(InputIt1 first1, InputIt1 last1, InputIt2 first2, OutputIt d_first, BinaryOperation binary_op); -template +template void generate(ForwardIt first, ForwardIt last, Generator g); #if CPPREFERENCE_STDVER >= 2011 -template +template OutputIt generate_n(OutputIt first, Size count, Generator g); #else -template +template void generate_n(OutputIt first, Size count, Generator g); #endif -template +template ForwardIt remove(ForwardIt first, ForwardIt last, const T& value); -template +template ForwardIt remove_if(ForwardIt first, ForwardIt last, UnaryPredicate p); -template +template OutputIt remove_copy(InputIt first, InputIt last, OutputIt d_first, const T& value); -template +template OutputIt remove_copy_if(InputIt first, InputIt last, OutputIt d_first, UnaryPredicate p); -template +template OutputIt remove_copy_if(InputIt first, InputIt last, OutputIt d_first, UnaryPredicate p); -template +template void replace_if(ForwardIt first, ForwardIt last, UnaryPredicate p, const T& new_value); -template +template OutputIt replace_copy(InputIt first, InputIt last, OutputIt d_first, const T& old_value, const T& new_value); -template +template OutputIt replace_copy_if(InputIt first, InputIt last, OutputIt d_first, UnaryPredicate p, const T& new_value); // defined in in C++11 #if CPPREFERENCE_STDVER >= 2011 -template +template void swap(T& a, T& b); #endif -template +template ForwardIt2 swap_ranges(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2); -template +template void iter_swap(ForwardIt1 a, ForwardIt2 b); -template +template void reverse(BidirIt first, BidirIt last); -template +template OutputIt reverse_copy(BidirIt first, BidirIt last, OutputIt d_first); #if CPPREFERENCE_STDVER >= 2011 -template +template ForwardIt rotate(ForwardIt first, ForwardIt n_first, ForwardIt last); #else -template +template void rotate(ForwardIt first, ForwardIt n_first, ForwardIt last); #endif -template +template OutputIt rotate_copy(ForwardIt first, ForwardIt n_first, ForwardIt last, OutputIt d_first); #if CPPREFERENCE_STDVER <2017 // deprecated in C++14 -template +template void random_shuffle(RandomIt first, RandomIt last); #endif #if CPPREFERENCE_STDVER <2011 -template +template void random_shuffle(RandomIt first, RandomIt last, RandomFunc&& r); #elif CPPREFERENCE_STDVER >= 2011 && CPPREFERENCE_STDVER <2017 // deprecated in C++14 -template +template void random_shuffle(RandomIt first, RandomIt last, RandomFunc& r); #endif #if CPPREFERENCE_STDVER >= 2011 -template +template void shuffle(RandomIt first, RandomIt last, URNG&& g); #endif -template +template ForwardIt unique(ForwardIt first, ForwardIt last); -template +template ForwardIt unique(ForwardIt first, ForwardIt last, BinaryPredicate p); -template +template OutputIt unique_copy(InputIt first, InputIt last, OutputIt d_first); -template +template OutputIt unique_copy(InputIt first, InputIt last, OutputIt d_first, BinaryPredicate p); #if CPPREFERENCE_STDVER >= 2011 -template +template bool is_partitioned(InputIt first, InputIt last, UnaryPredicate p); #endif #if CPPREFERENCE_STDVER <2011 -template +template BidirIt partition(BidirIt first, BidirIt last, UnaryPredicate p); #else -template +template ForwardIt partition(ForwardIt first, ForwardIt last, UnaryPredicate p); #endif #if CPPREFERENCE_STDVER >= 2011 template + class OutputIt2, class UnaryPredicate> std::pair partition_copy(InputIt first, InputIt last, OutputIt1 d_first_true, OutputIt2 d_first_false, UnaryPredicate p); #endif -template +template BidirIt stable_partition(BidirIt first, BidirIt last, UnaryPredicate p); #if CPPREFERENCE_STDVER >= 2011 -template +template ForwardIt partition_point(ForwardIt first, ForwardIt last, UnaryPredicate p); #endif #if CPPREFERENCE_STDVER >= 2011 -template +template bool is_sorted(ForwardIt first, ForwardIt last); -template +template bool is_sorted(ForwardIt first, ForwardIt last, Compare comp); -template +template ForwardIt is_sorted_until(ForwardIt first, ForwardIt last); -template +template ForwardIt is_sorted_until(ForwardIt first, ForwardIt last, Compare comp); #endif -template +template void sort(RandomIt first, RandomIt last); -template +template void sort(RandomIt first, RandomIt last, Compare comp); -template +template void partial_sort(RandomIt first, RandomIt middle, RandomIt last); -template +template void partial_sort(RandomIt first, RandomIt middle, RandomIt last, Compare comp); -template +template RandomIt partial_sort_copy(InputIt first, InputIt last, RandomIt d_first, RandomIt d_last); -template +template RandomIt partial_sort_copy(InputIt first, InputIt last, RandomIt d_first, RandomIt d_last, Compare comp); -template +template void stable_sort(RandomIt first, RandomIt last); -template +template void stable_sort(RandomIt first, RandomIt last, Compare comp); -template +template void nth_element(RandomIt first, RandomIt nth, RandomIt last); -template +template void nth_element(RandomIt first, RandomIt nth, RandomIt last, Compare comp); -template +template ForwardIt lower_bound(ForwardIt first, ForwardIt last, const T& value); -template +template ForwardIt lower_bound(ForwardIt first, ForwardIt last, const T& value, Compare comp); -template +template ForwardIt upper_bound(ForwardIt first, ForwardIt last, const T& value); -template +template ForwardIt upper_bound(ForwardIt first, ForwardIt last, const T& value, Compare comp); -template +template bool binary_search(ForwardIt first, ForwardIt last, const T& value); -template +template bool binary_search(ForwardIt first, ForwardIt last, const T& value, Compare comp); -template +template std::pair equal_range(ForwardIt first, ForwardIt last, const T& value); -template +template std::pair equal_range(ForwardIt first, ForwardIt last, const T& value, Compare comp); -template +template OutputIt merge(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first); @@ -415,274 +483,299 @@ OutputIt merge(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp); -template +template void inplace_merge(BidirIt first, BidirIt middle, BidirIt last); template void inplace_merge(BidirIt first, BidirIt middle, BidirIt last, Compare comp); -template +template bool includes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2); -template +template bool includes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp); -template +template OutputIt set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first); template + class OutputIt, class Compare> OutputIt set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp); -template +template OutputIt set_intersection(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first); template + class OutputIt, class Compare> OutputIt set_intersection(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp); -template +template OutputIt set_symmetric_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first); template + class OutputIt, class Compare> OutputIt set_symmetric_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp); -template +template OutputIt set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first); template + class OutputIt, class Compare> OutputIt set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp); #if CPPREFERENCE_STDVER >= 2011 -template +template bool is_heap(RandomIt first, RandomIt last); -template +template bool is_heap(RandomIt first, RandomIt last, Compare comp); -template +template RandomIt is_heap_until(RandomIt first, RandomIt last); -template +template RandomIt is_heap_until(RandomIt first, RandomIt last, Compare comp); #endif -template +template void make_heap(RandomIt first, RandomIt last); -template +template void make_heap(RandomIt first, RandomIt last, Compare comp); -template +template void push_heap(RandomIt first, RandomIt last); -template +template void push_heap(RandomIt first, RandomIt last, Compare comp); -template +template void pop_heap(RandomIt first, RandomIt last); -template +template void pop_heap(RandomIt first, RandomIt last, Compare comp); -template +template void sort_heap(RandomIt first, RandomIt last); -template +template void sort_heap(RandomIt first, RandomIt last, Compare comp); #if CPPREFERENCE_STDVER <2014 -template +template const T& max(const T& a, const T& b); -template +template const T& max(const T& a, const T& b, Compare comp); #else -template +template constexpr const T& max(const T& a, const T& b); -template +template constexpr const T& max(const T& a, const T& b, Compare comp); #endif #if CPPREFERENCE_STDVER >= 2011 -template +template T max(std::initializer_list ilist); -template +template T max(std::initializer_list ilist, Compare comp); #elif CPPREFERENCE_STDVER >= 2014 -template +template constexpr T max(std::initializer_list ilist); -template +template constexpr T max(std::initializer_list ilist, Compare comp); #endif #if CPPREFERENCE_STDVER <2017 -template +template ForwardIt max_element(ForwardIt first, ForwardIt last); -template +template ForwardIt max_element(ForwardIt first, ForwardIt last, Compare cmp); #else -template +template constexpr ForwardIt max_element(ForwardIt first, ForwardIt last); -template +template constexpr ForwardIt max_element(ForwardIt first, ForwardIt last, Compare cmp); #endif -#if CPPREFERENCE_STDVER <2014 -template -const T& min(const T& a, const T& b); - -template -const T& min(const T& a, const T& b, Compare comp); -#else -template +#if CPPREFERENCE_STDVER >= 2014 +template constexpr const T& min(const T& a, const T& b); -template +template constexpr const T& min(const T& a, const T& b, Compare comp); -#endif +#else +template +const T& min(const T& a, const T& b); -#if CPPREFERENCE_STDVER >= 2011 -template -T min(std::initializer_list ilist); +template +const T& min(const T& a, const T& b, Compare comp); +#endif -template -T min(std::initializer_list ilist, Compare comp); -#elif CPPREFERENCE_STDVER >= 2014 -template +#if CPPREFERENCE_STDVER >= 2014 +template constexpr T min(std::initializer_list ilist); -template +template constexpr T min(std::initializer_list ilist, Compare comp); +#elif CPPREFERENCE_STDVER >= 2011 +template +T min(std::initializer_list ilist); + +template +T min(std::initializer_list ilist, Compare comp); #endif #if CPPREFERENCE_STDVER <2017 -template +template ForwardIt min_element(ForwardIt first, ForwardIt last); -template +template ForwardIt min_element(ForwardIt first, ForwardIt last, Compare cmp); #else -template +template constexpr ForwardIt min_element(ForwardIt first, ForwardIt last); -template +template constexpr ForwardIt min_element(ForwardIt first, ForwardIt last, Compare cmp); #endif -#if CPPREFERENCE_STDVER >= 2011 && CPPREFERENCE_STDVER <2014 -template +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr std::pair minmax(const T& a, const T& b); + +template +constexpr std::pair minmax(const T& a, const T& b, + Compare comp); +template +constexpr std::pair minmax(std::initializer_list ilist); + +template +constexpr std::pair minmax(std::initializer_list ilist, Compare comp); + +#elif CPPREFERENCE_STDVER >= 2011 +template std::pair minmax(const T& a, const T& b); -template +template std::pair minmax(const T& a, const T& b, Compare comp); -template +template std::pair minmax(std::initializer_list ilist); -template +template std::pair minmax(std::initializer_list ilist, Compare comp); - -#elif CPPREFERENCE_STDVER >= 2014 -template -constexpr std::pair minmax(const T& a, const T& b); - -template -constexpr std::pair minmax(const T& a, const T& b, - Compare comp); -template -constexpr std::pair minmax(std::initializer_list ilist); - -template -constexpr std::pair minmax(std::initializer_list ilist, Compare comp); #endif #if CPPREFERENCE_STDVER >= 2011 && CPPREFERENCE_STDVER <2017 -template +template std::pair minmax_element(ForwardIt first, ForwardIt last); -template +template std::pair minmax_element(ForwardIt first, ForwardIt last, Compare comp); #elif CPPREFERENCE_STDVER >= 2017 -template +template constexpr std::pair minmax_element(ForwardIt first, ForwardIt last); -template +template constexpr std::pair minmax_element(ForwardIt first, ForwardIt last, Compare comp); #endif -template +#if CPPREFERENCE_STDVER >= 2017 +template +constexpr const T& clamp(const T& v, const T& lo, const T& hi); +template +constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); +#endif + +template bool lexicographical_compare(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2); -template +template bool lexicographical_compare(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp); -#if CPPREFERENCE_STDVER >= 2011 -template +#if CPPREFERENCE_STDVER >= 2020 +template +constexpr bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, + ForwardIt2 first2); + +template +constexpr bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, + ForwardIt2 first2, BinaryPredicate p); +#elif CPPREFERENCE_STDVER >= 2011 +template bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2); -template +template bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, BinaryPredicate p); #endif -#if CPPREFERENCE_STDVER >= 2011 -template +#if CPPREFERENCE_STDVER >= 2020 +template +constexpr bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, + ForwardIt2 first2, ForwardIt2 last2); + +template +constexpr bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, + ForwardIt2 first2, ForwardIt2 last2, + BinaryPredicate p); + +#elif CPPREFERENCE_STDVER >= 2011 +template bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, ForwardIt2 last2); -template +template bool is_permutation(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, ForwardIt2 last2, BinaryPredicate p); #endif -template +template bool next_permutation(BidirIt first, BidirIt last); -template +template bool next_permutation(BidirIt first, BidirIt last, Compare comp); -template +template bool prev_permutation(BidirIt first, BidirIt last); -template +template bool prev_permutation(BidirIt first, BidirIt last, Compare comp); } // namespace std diff --git a/headers/array b/headers/array index 29698105c..020f29d5e 100644 --- a/headers/array +++ b/headers/array @@ -46,13 +46,6 @@ public: typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - // constructor - array& operator=(const array& other); -#if CPPREFERENCE_STDVER>= 2011 - array& operator=(array&& other); - array& operator=(initializer_list ilist); -#endif - void assign(size_type count, const value_type& value); template void assign(InputIt first, InputIt last); @@ -60,18 +53,49 @@ public: void assign(std::initializer_list ilist); #endif - allocator_type get_allocator() const; - // element access +#if CPPREFERENCE_STDVER >= 2017 + constexpr reference at(size_type n); + constexpr const_reference at(size_type n) const; +#else reference at(size_type n); const_reference at(size_type n) const; - reference operator[](size_type n); +#endif + +#if CPPREFERENCE_STDVER >= 2017 + constexpr reference operator[](size_type n); +#else + reference operator[](size_type n); +#endif +#if CPPREFERENCE_STDVER >= 2014 + constexpr const_reference operator[](size_type n) const; +#else const_reference operator[](size_type n) const; +#endif - reference front(); +#if CPPREFERENCE_STDVER >= 2017 + constexpr reference front(); +#else + reference front(); +#endif + +#if CPPREFERENCE_STDVER >= 2014 + constexpr const_reference front() const; +#else const_reference front() const; - reference back(); +#endif + +#if CPPREFERENCE_STDVER >= 2017 + constexpr reference back(); +#else + reference back(); +#endif + +#if CPPREFERENCE_STDVER >= 2014 + constexpr const_reference back() const; +#else const_reference back() const; +#endif T* data(); const T* data() const; @@ -94,11 +118,17 @@ public: bool empty() const; size_type size() const; - size_type max_size() const; +#if CPPREFERENCE_STDVER >= 2014 + constexpr size_type max_size() const; +#else + constexpr size_type max_size(); +#endif void fill(const T& value); void swap(array& other); + + T internal_data[N]; // exposure-only }; template diff --git a/headers/atomic b/headers/atomic index d246cc5ff..0142c7ba2 100644 --- a/headers/atomic +++ b/headers/atomic @@ -16,6 +16,9 @@ #ifndef CPPREFERENCE_ATOMIC_H #define CPPREFERENCE_ATOMIC_H +#include // for ptrdiff_t +#include + namespace std { #if CPPREFERENCE_STDVER>= 2011 @@ -127,9 +130,9 @@ struct atomic { // member of atomic T fetch_xor(T arg, - memory_xorder = std::memory_xorder_seq_cst); + memory_order = std::memory_order_seq_cst); T fetch_xor(T arg, - memory_xorder = std::memory_xorder_seq_cst) volatile; + memory_order = std::memory_order_seq_cst) volatile; // member of atomic T operator++(); diff --git a/headers/bitset b/headers/bitset index e868f7095..c457ceddc 100644 --- a/headers/bitset +++ b/headers/bitset @@ -16,6 +16,10 @@ #ifndef CPPREFERENCE_BITSET_H #define CPPREFERENCE_BITSET_H +#include // for size_t +#include +#include + namespace std { template @@ -128,10 +132,10 @@ bitset operator^(const bitset& lhs, const bitset& rhs); template std::basic_ostream& operator<<(std::basic_ostream& os, - const bitset& x); + const bitset& x); template std::basic_istream& operator>>(std::basic_istream& is, - bitset& x); + bitset& x); } // namespace std diff --git a/headers/chrono b/headers/chrono index 9833e88b5..e701d6156 100644 --- a/headers/chrono +++ b/headers/chrono @@ -18,6 +18,9 @@ #if CPPREFERENCE_STDVER>= 2011 #include +#include // for time_t +#include +#include namespace std { namespace chrono { @@ -35,7 +38,7 @@ public: duration& operator=(const duration& other) = default; - constexpr rep count() const; + constexpr Rep count() const; static constexpr duration zero(); static constexpr duration min(); @@ -51,9 +54,9 @@ public: duration& operator+=(const duration& d); duration& operator-=(const duration& d); - duration& operator*=(const rep& rhs); - duration& operator/=(const rep& rhs); - duration& operator%=(const rep& rhs); + duration& operator*=(const Rep& rhs); + duration& operator/=(const Rep& rhs); + duration& operator%=(const Rep& rhs); duration& operator%=(const duration& rhs); }; @@ -132,6 +135,12 @@ typedef duration milliseconds; typedef duration seconds; typedef duration> minutes; typedef duration> hours; +#if CPPREFERENCE_STDVER >= 2020 +using days = duration>; +using weeks = duration>; +using months = duration>; +using years = duration>; +#endif template struct treat_as_floating_point : std::is_floating_point {}; @@ -157,16 +166,26 @@ public: #else typedef Clock clock; typedef Duration duration; - typedef Duration::rep rep; - typedef Duration::period period; + typedef typename Duration::rep rep; + typedef typename Duration::period period; #endif +#if CPPREFERENCE_STDVER >= 2014 + constexpr time_point(); + constexpr explicit time_point(const duration& d); + + template + constexpr time_point(const time_point& t); + + constexpr duration time_since_epoch() const; +#else time_point(); explicit time_point(const duration& d); template time_point(const time_point& t); duration time_since_epoch() const; +#endif time_point& operator+=(const duration& d); time_point& operator-=(const duration& d); @@ -216,8 +235,15 @@ template bool operator>=(const time_point& lhs, const time_point& rhs); +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr time_point time_point_cast( + const time_point& t); +#else template -time_point time_point_cast(const time_point& t); +time_point time_point_cast( + const time_point& t); +#endif class system_clock { public: @@ -226,13 +252,33 @@ public: typedef duration duration; typedef time_point time_point; - constexpr static bool is_steady; + constexpr static bool is_steady = false; static std::chrono::time_point now(); static std::time_t to_time_t(const time_point& t); static std::chrono::system_clock::time_point from_time_t(std::time_t t); }; +#if CPPREFERENCE_STDVER >= 2020 +template +using sys_time = time_point; + +using sys_seconds = sys_time; +using sys_days = sys_time; + +template > +basic_istream& + from_stream(basic_istream& is, const CharT* fmt, + sys_time& time_point, + basic_string* abbrev = nullptr, + minutes* offset = nullptr); + +template +basic_ostream& + operator<<(basic_ostream& os, + const sys_time& time_point); +#endif + class steady_clock { public: typedef int rep; // SIMPLIFIED: actually unspecified @@ -240,7 +286,7 @@ public: typedef duration duration; typedef time_point time_point; - constexpr static bool is_steady; + constexpr static bool is_steady = false; static std::chrono::time_point now(); }; @@ -252,11 +298,87 @@ public: typedef duration duration; typedef time_point time_point; - constexpr static bool is_steady; + constexpr static bool is_steady = false; static std::chrono::time_point now(); }; +#if CPPREFERENCE_STDVER >= 2020 +class utc_clock { +public: + using rep = int; // SIMPLIFIED: actually unspecified + using period = ratio<1>; // SIMPLIFIED: actually unspecified + using duration = std::chrono::duration; + using time_point = std::chrono::time_point; + + static time_point now(); + + template + static sys_time> + to_sys(const std::chrono::time_point& t); + + template + static std::chrono::time_point> + from_sys(const sys_time& t); +}; + +template +using utc_time = time_point; + +using utc_seconds = utc_time; + +template > +basic_istream& + from_stream(basic_istream& is, const CharT* fmt, + utc_time& time_point, + basic_string* abbrev = nullptr, + minutes* offset = nullptr); + +template +basic_ostream& + operator<<(basic_ostream& os, const chrono::utc_time& time_point); + +class file_clock { +public: + using rep = int; // SIMPLIFIED: actually unspecified + using period = std::ratio<1>; // SIMPLIFIED: actually unspecified + using duration = duration; + using time_point = time_point; + + static time_point now(); + + template + static sys_time> + to_sys(const std::chrono::time_point& t); + + template + static std::chrono::time_point> + from_sys(const sys_time& t); + + template + static utc_time> + to_utc(const std::chrono::time_point& t); + + template + static std::chrono::time_point> + from_utc(const utc_time& t); +}; + +template +using file_time = time_point; + +template > +basic_istream& + from_stream(basic_istream& is, const CharT* fmt, + file_time& time_point, + basic_string* abbrev = nullptr, + minutes* offset = nullptr); + +template +basic_ostream& + operator<<(basic_ostream& os, const file_time& time_point); +#endif + } // namespace chrono } // namespace std diff --git a/headers/cmath b/headers/cmath index 567aa370b..b52b12274 100644 --- a/headers/cmath +++ b/headers/cmath @@ -37,6 +37,11 @@ typedef float float_t; typedef double double_t; #endif // CPPREFERENCE_STDVER>= 2011 +// Workaround system headers being inluded and defining isnan +#ifdef isnan +#undef isnan +#endif + float abs(float arg); double abs(double arg); long double abs(long double arg); diff --git a/headers/codecvt b/headers/codecvt index 477ca7798..5701fac90 100644 --- a/headers/codecvt +++ b/headers/codecvt @@ -18,6 +18,10 @@ #if CPPREFERENCE_STDVER >= 2011 +#include // for size_t +#include // for mbstate_t +#include // for codecvt + namespace std { enum codecvt_mode { @@ -26,11 +30,10 @@ enum codecvt_mode { little_endian = 1 }; -template < - class Elem, - unsigned long Maxcode = 0x10ffff, - std::codecvt_mode Mode = (std::codecvt_mode)0 - > class codecvt_utf8 : public std::codecvt { +template(0)> +class codecvt_utf8 : public std::codecvt { public: explicit codecvt_utf8(std::size_t refs = 0); ~codecvt_utf8(); @@ -38,7 +41,7 @@ public: template + std::codecvt_mode Mode = static_cast(0)> class codecvt_utf16 : public std::codecvt { public: explicit codecvt_utf16(std::size_t refs = 0); @@ -47,7 +50,7 @@ public: template + std::codecvt_mode Mode = static_cast(0)> class codecvt_utf8_utf16 : public std::codecvt { public: explicit codecvt_utf8_utf16(std::size_t refs = 0); diff --git a/headers/compare b/headers/compare new file mode 100644 index 000000000..66e59fc36 --- /dev/null +++ b/headers/compare @@ -0,0 +1,121 @@ +/* Copyright (C) 2022 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_COMPARE_H +#define CPPREFERENCE_COMPARE_H + +#if CPPREFERENCE_STDVER >= 2020 +namespace std { + +class partial_ordering { +public: + struct __unspec {}; + + static const partial_ordering less; + static const partial_ordering equivalent; + static const partial_ordering greater; + static const partial_ordering unordered; + + friend constexpr bool operator==(partial_ordering a, __unspec b) noexcept; + friend constexpr bool operator==(partial_ordering a, partial_ordering b) noexcept; + friend constexpr bool operator<(partial_ordering a, __unspec b) noexcept; + friend constexpr bool operator<(__unspec a, partial_ordering b) noexcept; + friend constexpr bool operator<=(partial_ordering a, __unspec b) noexcept; + friend constexpr bool operator<=(__unspec a, partial_ordering b) noexcept; + friend constexpr bool operator>(partial_ordering a, __unspec b) noexcept; + friend constexpr bool operator>(__unspec a, partial_ordering b) noexcept; + friend constexpr bool operator>=(partial_ordering a, __unspec b) noexcept; + friend constexpr bool operator>=(__unspec a, partial_ordering b) noexcept; + friend constexpr bool operator<=>(partial_ordering a, __unspec b) noexcept; + friend constexpr bool operator<=>(__unspec a, partial_ordering b) noexcept; +}; + +class weak_ordering { +public: + struct __unspec {}; + + static const weak_ordering less; + static const weak_ordering equivalent; + static const weak_ordering greater; + + constexpr operator partial_ordering() const noexcept; + + friend constexpr bool operator==(weak_ordering a, __unspec b) noexcept; + friend constexpr bool operator==(weak_ordering a, weak_ordering b) noexcept; + friend constexpr bool operator<(weak_ordering a, __unspec b) noexcept; + friend constexpr bool operator<(__unspec a, weak_ordering b) noexcept; + friend constexpr bool operator<=(weak_ordering a, __unspec b) noexcept; + friend constexpr bool operator<=(__unspec a, weak_ordering b) noexcept; + friend constexpr bool operator>(weak_ordering a, __unspec b) noexcept; + friend constexpr bool operator>(__unspec a, weak_ordering b) noexcept; + friend constexpr bool operator>=(weak_ordering a, __unspec b) noexcept; + friend constexpr bool operator>=(__unspec a, weak_ordering b) noexcept; + friend constexpr bool operator<=>(weak_ordering a, __unspec b) noexcept; + friend constexpr bool operator<=>(__unspec a, weak_ordering b) noexcept; +}; + + +class strong_ordering { +public: + struct __unspec {}; + + static const strong_ordering less; + static const strong_ordering equal; + static const strong_ordering equivalent; + static const strong_ordering greater; + + constexpr operator partial_ordering() const noexcept; + constexpr operator weak_ordering() const noexcept; + + friend constexpr bool operator==(strong_ordering a, __unspec b) noexcept; + friend constexpr bool operator==(strong_ordering a, strong_ordering b) noexcept; + friend constexpr bool operator<(strong_ordering a, __unspec b) noexcept; + friend constexpr bool operator<(__unspec a, strong_ordering b) noexcept; + friend constexpr bool operator<=(strong_ordering a, __unspec b) noexcept; + friend constexpr bool operator<=(__unspec a, strong_ordering b) noexcept; + friend constexpr bool operator>(strong_ordering a, __unspec b) noexcept; + friend constexpr bool operator>(__unspec a, strong_ordering b) noexcept; + friend constexpr bool operator>=(strong_ordering a, __unspec b) noexcept; + friend constexpr bool operator>=(__unspec a, strong_ordering b) noexcept; + friend constexpr bool operator<=>(strong_ordering a, __unspec b) noexcept; + friend constexpr bool operator<=>(__unspec a, strong_ordering b) noexcept; +}; + +constexpr bool is_eq(partial_ordering cmp) noexcept; +constexpr bool is_neq(partial_ordering cmp) noexcept; +constexpr bool is_lt(partial_ordering cmp) noexcept; +constexpr bool is_lteq(partial_ordering cmp) noexcept; +constexpr bool is_gt(partial_ordering cmp) noexcept; +constexpr bool is_gteq(partial_ordering cmp) noexcept; + +template +struct common_comparison_category { + using type = partial_ordering; // SIMPLIFIED +}; + +template +using common_comparison_category_t = typename common_comparison_category::type; + +template struct compare_three_way_result; + +template +using compare_three_way_result_t = typename compare_three_way_result::type; + +struct compare_three_way; + +} // namespace std +#endif // CPPREFERENCE_STDVER >= 2020 + +#endif // CPPREFERENCE_COMPARE_H diff --git a/headers/complex b/headers/complex index 086a86391..6e3e25230 100644 --- a/headers/complex +++ b/headers/complex @@ -16,6 +16,8 @@ #ifndef CPPREFERENCE_COMPLEX_H #define CPPREFERENCE_COMPLEX_H +#include + namespace std { template @@ -23,23 +25,48 @@ class complex { public: typedef T value_type; +#if CPPREFERENCE_STDVER >= 2014 + constexpr complex(const T& re = T(), const T& im = T()); + + constexpr complex(const complex& other); + + template + constexpr complex(const complex& other); +#else complex(const T& re = T(), const T& im = T()); complex(const complex& other); template complex(const complex& other); +#endif complex& operator=(const T& x); template complex& operator=(const complex& cx); +#if CPPREFERENCE_STDVER >= 2014 + constexpr T real() const; +#else T real() const; +#endif +#if CPPREFERENCE_STDVER >= 2020 + constexpr void real(T value); +#else void real(T value); +#endif +#if CPPREFERENCE_STDVER >= 2014 + constexpr T imag() const; +#else T imag() const; +#endif +#if CPPREFERENCE_STDVER >= 2020 + constexpr void imag(T value); +#else void imag(T value); +#endif complex& operator+=(const T& other); @@ -61,11 +88,11 @@ public: template complex& operator/=(const complex& other); - template - complex operator+(const complex& val); + template + complex operator+(const complex& val); - template - complex operator-(const complex& val); + template + complex operator-(const complex& val); }; template @@ -104,6 +131,20 @@ complex operator/(const complex& lhs, const T& rhs); template complex operator/(const T& lhs, const complex& rhs); +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr bool operator==(const complex& lhs, const complex& rhs); +template +constexpr bool operator!=(const complex& lhs, const complex& rhs); +template +constexpr bool operator<(const complex& lhs, const complex& rhs); +template +constexpr bool operator<=(const complex& lhs, const complex& rhs); +template +constexpr bool operator>(const complex& lhs, const complex& rhs); +template +constexpr bool operator>=(const complex& lhs, const complex& rhs); +#else template bool operator==(const complex& lhs, const complex& rhs); template @@ -116,6 +157,8 @@ template bool operator>(const complex& lhs, const complex& rhs); template bool operator>=(const complex& lhs, const complex& rhs); +#endif + template std::basic_ostream& @@ -127,11 +170,19 @@ std::basic_istream& operator>>(std::basic_istream& is, std::complex& x); +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr T real(const complex& z); + +template +constexpr T imag(const complex& z); +#else template T real(const complex& z); template T imag(const complex& z); +#endif template T abs(const complex& z); diff --git a/headers/condition_variable b/headers/condition_variable index a05f1fc90..66db3a9f2 100644 --- a/headers/condition_variable +++ b/headers/condition_variable @@ -18,6 +18,8 @@ #if CPPREFERENCE_STDVER>= 2011 +#include // for unique_lock + namespace std { enum class cv_status { diff --git a/headers/csetjmp b/headers/csetjmp index c867e1530..aef488b96 100644 --- a/headers/csetjmp +++ b/headers/csetjmp @@ -24,6 +24,6 @@ void longjmp(std::jmp_buf env, int status); } // namespace std -void setjmp(jmp_buf buf); // actually a macro +void setjmp(std::jmp_buf buf); // actually a macro #endif // CPPREFERENCE_CSETJMP_H diff --git a/headers/cstdarg b/headers/cstdarg index 038c09f14..f0673077f 100644 --- a/headers/cstdarg +++ b/headers/cstdarg @@ -18,16 +18,32 @@ namespace std { -struct va_list; // actually a typedef +#ifdef va_start +typedef ::va_list va_list; +#else +struct va_list {}; // actually a typedef +#endif } // namespace std -void va_start(std::va_list ap, int parm_n); // actually a macro +#ifndef va_start +template +void va_start(std::va_list ap, T parm_n); // actually a macro +#endif + +#ifndef va_arg #define va_arg(x, T) T() +#endif + #if CPPREFERENCE_STDVER>= 2011 +#ifndef va_copy void va_copy(std::va_list desc, std::va_list src); // actually a macro #endif +#endif + +#ifndef va_end void va_end(std::va_list ap); // actually a macro +#endif #endif // CPPREFERENCE_CSTDARG_H diff --git a/headers/cstddef b/headers/cstddef index 7e8ac2349..9bb8598db 100644 --- a/headers/cstddef +++ b/headers/cstddef @@ -16,21 +16,61 @@ #ifndef CPPREFERENCE_CSTDDEF_H #define CPPREFERENCE_CSTDDEF_H -namespace std { - #ifndef offsetof #define offsetof(type,member_designator) 0 // SIMPLIFIED #endif #ifndef NULL -#define NULL +#define NULL 0 #endif namespace std { // dummy impl -typedef long long ptrdiff_t; -typedef long long size_t; -typedef long long max_align_t; + +typedef long ptrdiff_t; +typedef unsigned long size_t; +typedef long max_align_t; +#if CPPREFERENCE_STDVER >= 2011 +#if CPPREFERENCE_SIMPLIFY_TYPEDEFS typedef void* nullptr_t; +#else +typedef decltype(nullptr) nullptr_t; +#endif +#endif + +#if CPPREFERENCE_STDVER >= 2017 +enum class byte : unsigned char {}; + +template +constexpr IntegerType to_integer(std::byte b) noexcept; + +constexpr std::byte operator|(std::byte l, std::byte r) noexcept; +constexpr std::byte operator&(std::byte l, std::byte r) noexcept; +constexpr std::byte operator^(std::byte l, std::byte r) noexcept; +constexpr std::byte operator~(std::byte b) noexcept; + +constexpr std::byte& operator|=(std::byte& l, std::byte r) noexcept; +constexpr std::byte& operator&=(std::byte& l, std::byte r) noexcept; +constexpr std::byte& operator^=(std::byte& l, std::byte r) noexcept; + +template +constexpr std::byte operator<<(std::byte b, IntegerType shift) noexcept; + +template +constexpr std::byte operator>>(std::byte b, IntegerType shift) noexcept; + +template +constexpr std::byte& operator<<=(std::byte& b, IntegerType shift) noexcept; + +template +constexpr std::byte& operator>>=(std::byte& b, IntegerType shift) noexcept; +#endif + } // namespace std +#if !CPPREFERENCE_INT_TYPES_ONLY_IN_STD +using std::ptrdiff_t; +using std::size_t; +using std::max_align_t; +#endif // !CPPREFERENCE_INT_TYPES_ONLY_IN_STD + #endif // CPPREFERENCE_CSTDDEF_H diff --git a/headers/cstdint b/headers/cstdint index 0e84cb082..d97d2b671 100644 --- a/headers/cstdint +++ b/headers/cstdint @@ -142,4 +142,36 @@ typedef unsigned long long uintmax_t; } // namespace std #endif // CPPREFERENCE_STDVER>= 2011 +#if !CPPREFERENCE_INT_TYPES_ONLY_IN_STD +using std::int8_t; +using std::int16_t; +using std::int32_t; +using std::int64_t; +using std::uint8_t; +using std::uint16_t; +using std::uint32_t; +using std::uint64_t; +using std::int_fast8_t; +using std::int_fast16_t; +using std::int_fast32_t; +using std::int_fast64_t; +using std::uint_fast8_t; +using std::uint_fast16_t; +using std::uint_fast32_t; +using std::uint_fast64_t; +using std::int_least8_t; +using std::int_least16_t; +using std::int_least32_t; +using std::int_least64_t; +using std::uint_least8_t; +using std::uint_least16_t; +using std::uint_least32_t; +using std::uint_least64_t; + +using std::intptr_t; +using std::uintptr_t; +using std::intmax_t; +using std::uintmax_t; +#endif + #endif // CPPREFERENCE_CSTDINT_H diff --git a/headers/cstdio b/headers/cstdio index f4f0198cf..331e3c37a 100644 --- a/headers/cstdio +++ b/headers/cstdio @@ -16,9 +16,10 @@ #ifndef CPPREFERENCE_CSTDIO_H #define CPPREFERENCE_CSTDIO_H -#define stdin (::std::FILE*)(NULL) // actually a valid pointer -#define stdout (::std::FILE*)(NULL) -#define stderr (::std::FILE*)(NULL) +#define stdin (reinterpret_cast<::std::FILE*>(NULL)) // actually a valid pointer +#define stdout (reinterpret_cast<::std::FILE*>(NULL)) +#define stderr (reinterpret_cast<::std::FILE*>(NULL)) + #define EOR 0 #define FOPEN_MAX 0 #define FILENAME_MAX 0 @@ -32,6 +33,9 @@ #define TMP_MAX 0 #define L_tmpnam 0 +#include +#include + namespace std { struct FILE; @@ -62,7 +66,7 @@ int fscanf(std::FILE* stream, const char* format, ...); int sscanf(const char* buffer, const char* format, ...); #if CPPREFERENCE_STDVER>= 2011 -int vscanf(const char* format, v_list vlist); +int vscanf(const char* format, va_list vlist); int vfscanf(std::FILE* stream, const char* format, va_list vlist); int vsscanf(const char* buffer, const char* format, va_list vlist); #endif diff --git a/headers/cstdlib b/headers/cstdlib index 0b838a51b..0d18b0f2b 100644 --- a/headers/cstdlib +++ b/headers/cstdlib @@ -16,6 +16,8 @@ #ifndef CPPREFERENCE_CSTDLIB_H #define CPPREFERENCE_CSTDLIB_H +#include + namespace std { // math utils diff --git a/headers/cstring b/headers/cstring index 131b33f0c..f019f3ef9 100644 --- a/headers/cstring +++ b/headers/cstring @@ -16,6 +16,8 @@ #ifndef CPPREFERENCE_CSTRING_H #define CPPREFERENCE_CSTRING_H +#include // for size_t + namespace std { char* strcpy(char* dest, const char* src); diff --git a/headers/ctime b/headers/ctime index 90cb50048..660b89acf 100644 --- a/headers/ctime +++ b/headers/ctime @@ -16,6 +16,8 @@ #ifndef CPPREFERENCE_CTIME_H #define CPPREFERENCE_CTIME_H +#include // for size_t + #define CLOCKS_PER_SEC 0 // unspecified namespace std { diff --git a/headers/cuchar b/headers/cuchar index d6dde80df..faccadfd2 100644 --- a/headers/cuchar +++ b/headers/cuchar @@ -18,8 +18,17 @@ #if CPPREFERENCE_STDVER>= 2011 +#include // for size_t +#include // for mbstate_t + +#ifndef __STDC_UTF_16__ #define __STDC_UTF_16__ +#endif + +#ifndef __STDC_UTF_16__ #define __STDC_UTF_32__ +#endif + namespace std { std::size_t mbrtoc16(char16_t* pc16, diff --git a/headers/cwchar b/headers/cwchar index 35f1a6445..9c8a2ef4e 100644 --- a/headers/cwchar +++ b/headers/cwchar @@ -16,6 +16,10 @@ #ifndef CPPREFERENCE_CWCHAR_H #define CPPREFERENCE_CWCHAR_H +#include // for size_t +#include // for wint_t +#include // for FILE + namespace std { // wide strings diff --git a/headers/deque b/headers/deque index 894c7766a..41757c0c2 100644 --- a/headers/deque +++ b/headers/deque @@ -70,6 +70,7 @@ public: deque(size_type count, const T& value, const Allocator& alloc = Allocator()); +#endif #if CPPREFERENCE_STDVER <2014 explicit deque(size_type n); @@ -185,7 +186,10 @@ public: void push_back(T&& value); #endif -#if CPPREFERENCE_STDVER>= 2011 +#if CPPREFERENCE_STDVER >= 2017 + template + reference emplace_back(Args&& ... args); +#elif CPPREFERENCE_STDVER >= 2011 template void emplace_back(Args&& ... args); #endif @@ -197,7 +201,10 @@ public: void push_front(T&& value); #endif -#if CPPREFERENCE_STDVER>= 2011 +#if CPPREFERENCE_STDVER >= 2017 + template + reference emplace_front(Args&& ... args); +#elif CPPREFERENCE_STDVER >= 2011 template void emplace_front(Args&& ... args); #endif diff --git a/headers/detail/cppreference_unspecified b/headers/detail/cppreference_unspecified new file mode 100644 index 000000000..3e4476c9e --- /dev/null +++ b/headers/detail/cppreference_unspecified @@ -0,0 +1,35 @@ +/* Copyright (C) 2019 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_DETAIL_CPPREFERENCE_UNSPECIFIED_H +#define CPPREFERENCE_DETAIL_CPPREFERENCE_UNSPECIFIED_H + +// this is non-standard header + +namespace std { + +#if CPPREFERENCE_STDVER >= 2011 +using CPPREFERENCE_UNSPECIFIED_TYPE = int; +constexpr int CPPREFERENCE_UNSPECIFIED_TYPE_VALUE = 0; +using CPPREFERENCE_SIMPLIFIED_TYPE = int; +#else +typedef int CPPREFERENCE_UNSPECIFIED_TYPE; +static const int CPPREFERENCE_UNSPECIFIED_TYPE_VALUE = 0; +typedef int CPPREFERENCE_SIMPLIFIED_TYPE; +#endif + +} // namespace std + +#endif // CPPREFERENCE_DETAIL_LOCALE_FWD_H diff --git a/headers/detail/locale_fwd b/headers/detail/locale_fwd new file mode 100644 index 000000000..e67b51170 --- /dev/null +++ b/headers/detail/locale_fwd @@ -0,0 +1,27 @@ +/* Copyright (C) 2019 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_DETAIL_LOCALE_FWD_H +#define CPPREFERENCE_DETAIL_LOCALE_FWD_H + +// this is non-standard header + +namespace std { + +class locale; + +} // namespace std + +#endif // CPPREFERENCE_DETAIL_LOCALE_FWD_H diff --git a/headers/detail/string_fwd b/headers/detail/string_fwd new file mode 100644 index 000000000..dedac0922 --- /dev/null +++ b/headers/detail/string_fwd @@ -0,0 +1,42 @@ +/* Copyright (C) 2019 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_DETAIL_STRING_FWD_H +#define CPPREFERENCE_DETAIL_STRING_FWD_H + +// this is non-standard header + +namespace std { + +template struct char_traits; + +template class allocator; + +template < + class CharT, + class Traits = std::char_traits, + class Allocator = std::allocator +> class basic_string; + +typedef basic_string string; +typedef basic_string wstring; +#if CPPREFERENCE_STDVER>= 2011 +typedef basic_string u16string; +typedef basic_string u32string; +#endif + +} // namespace std + +#endif // CPPREFERENCE_DETAIL_STRING_FWD_H diff --git a/headers/detail/string_view_fwd b/headers/detail/string_view_fwd new file mode 100644 index 000000000..477ef6f9d --- /dev/null +++ b/headers/detail/string_view_fwd @@ -0,0 +1,35 @@ +/* Copyright (C) 2019 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_DETAIL_STRING_VIEW_FWD_H +#define CPPREFERENCE_DETAIL_STRING_VIEW_FWD_H + +// this is non-standard header + +namespace std { + +template struct char_traits; + +template> +class basic_string_view; + +using string_view = basic_string_view; +using wstring_view = basic_string_view; +using u16string_view = basic_string_view; +using u32string_view = basic_string_view; + +} // namespace std + +#endif // CPPREFERENCE_DETAIL_STRING_VIEW_FWD_H diff --git a/headers/exception b/headers/exception index 1481710b9..841df33a7 100644 --- a/headers/exception +++ b/headers/exception @@ -22,11 +22,14 @@ class exception { public: exception(); exception(const exception& other); + virtual ~exception(); exception& operator=(const exception& other); virtual const char* what() const; }; #if CPPREFERENCE_STDVER>= 2011 +typedef void* exception_ptr; // actually unspecified + class nested_exception { public: nested_exception(); @@ -50,9 +53,7 @@ void unexpected(); typedef void (*unexpected_handler)(); typedef void (*terminate_handler)(); -#if CPPREFERENCE_STDVER>= 2011 -typedef void* exception_ptr; // actually unspecified -#endif // CPPREFERENCE_STDVER>= 2011 + bool uncaught_exception(); #if CPPREFERENCE_STDVER>= 2017 diff --git a/headers/filesystem b/headers/filesystem new file mode 100644 index 000000000..f71dff866 --- /dev/null +++ b/headers/filesystem @@ -0,0 +1,593 @@ +/* Copyright (C) 2022 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_FILESYSTEM_H +#define CPPREFERENCE_FILESYSTEM_H + +#if CPPREFERENCE_STDVER >= 2017 + +#include +#include +#include +#include +#include + +namespace std::filesystem { + +enum class file_type { + none, + not_found, + regular, + directory, + symlink, + block, + character, + fifo, + socket, + unknown +}; + +enum class perms { + none, + owner_read, + owner_write, + owner_exec, + owner_all, + group_read, + group_write, + group_exec, + group_all, + others_read, + others_write, + others_exec, + others_all, + all, + set_uid, + set_gid, + sticky_bit, + mask, + unknown, +}; + +enum class perm_options { + replace, + add, + remove, + nofollow +}; + +enum class copy_options { + none, + skip_existing, + overwrite_existing, + update_existing, + recursive, + copy_symlinks, + skip_symlinks, + directories_only, + create_symlinks, + create_hard_links, +}; + +enum class directory_options { + none, + follow_directory_symlink, + skip_permission_denied, +}; + +class path { +public: + using value_type = char; // SIMPLIFIED, actually implementation-dependent + using string_type = basic_string; + static constexpr value_type preferred_separator = '/'; + + enum format { + native_format, + generic_format, + auto_format + }; + + path() noexcept; + path(const path& other); + path(path&& other) noexcept; + path(string_type&& source, format fmt = auto_format); + + template + path(const Source& source, format fmt = auto_format); + + template + path(InputIt first, InputIt last, format fmt = auto_format); + + template + path(const Source& source, const locale& loc, format fmt = auto_format); + + template + path(InputIt first, InputIt last, const locale& loc, format fmt = auto_format); + + ~path(); + + path& operator=(const path& other); + path& operator=(path&& other) noexcept; + path& operator=(string_type&& source); + + path& assign(string_type&& source); + + template + path& operator=(const Source& source); + + template + path& assign(const Source& source); + + template + path& assign(InputIt first, InputIt last); + + path& operator/=(const path& p); + + template + path& operator/=(const Source& source); + + template + path& append(const Source& source); + + template + path& append(InputIt first, InputIt last); + + path& operator+=(const path& x); + path& operator+=(const string_type& x); + path& operator+=(basic_string_view x); + path& operator+=(const value_type* x); + path& operator+=(value_type x); + + template + path& operator+=(const Source& x); + + template + path& operator+=(ECharT x); + + template + path& concat(const Source& x); + + template + path& concat(InputIt first, InputIt last); + + void clear() noexcept; + path& make_preferred(); + path& remove_filename(); + path& replace_filename(const path& replacement); + path& replace_extension(const path& replacement = path()); + void swap(path& rhs) noexcept; + + const string_type& native() const noexcept; + const value_type* c_str() const noexcept; + operator string_type() const; + + template, + class Allocator = allocator> + basic_string + string(const Allocator& a = Allocator()) const; + + std::string string() const; + std::wstring wstring() const; +#if CPPREFERENCE_STDVER >= 2020 + std::u8string u8string() const; +#endif + std::u16string u16string() const; + std::u32string u32string() const; + + // generic format observers + template, + class Allocator = allocator> + basic_string + generic_string(const Allocator& a = Allocator()) const; + + std::string generic_string() const; + std::wstring generic_wstring() const; +#if CPPREFERENCE_STDVER >= 2020 + std::u8string generic_u8string() const; +#endif + std::u16string generic_u16string() const; + std::u32string generic_u32string() const; + + int compare(const path& p) const noexcept; + int compare(const string_type& s) const; + int compare(basic_string_view s) const; + int compare(const value_type* s) const; + + path root_name() const; + path root_directory() const; + path root_path() const; + path relative_path() const; + path parent_path() const; + path filename() const; + path stem() const; + path extension() const; + + [[nodiscard]] bool empty() const noexcept; + bool has_root_name() const; + bool has_root_directory() const; + bool has_root_path() const; + bool has_relative_path() const; + bool has_parent_path() const; + bool has_filename() const; + bool has_stem() const; + bool has_extension() const; + bool is_absolute() const; + bool is_relative() const; + + path lexically_normal() const; + path lexically_relative(const path& base) const; + path lexically_proximate(const path& base) const; + + class iterator; + using const_iterator = iterator; + + iterator begin() const; + iterator end() const; + +#if CPPREFERENCE_STDVER >= 2020 + friend strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept; +#else + friend bool operator==(const path& lhs, const path& rhs) noexcept; + friend bool operator!=(const path& lhs, const path& rhs) noexcept; + friend bool operator>(const path& lhs, const path& rhs) noexcept; + friend bool operator>=(const path& lhs, const path& rhs) noexcept; + friend bool operator<(const path& lhs, const path& rhs) noexcept; + friend bool operator<=(const path& lhs, const path& rhs) noexcept; +#endif + friend path operator/(const path& lhs, const path& rhs); +}; + +void swap(path& lhs, path& rhs) noexcept; +size_t hash_value(const path& p) noexcept; + +// deprecated +template +path u8path(const Source& source); + +template +path u8path(InputIt first, InputIt last); + +template +basic_ostream& + operator<<(basic_ostream& os, const path& p); + +template +basic_istream& + operator>>(basic_istream& is, path& p); + +class filesystem_error : public system_error { +public: + filesystem_error(const string& what, error_code ec); + filesystem_error(const string& what, const path& path1, error_code ec); + filesystem_error(const string& what_arg, const path& path1, const path& path2, error_code ec); + + const path& path1() const noexcept; + const path& path2() const noexcept; + const char* what() const noexcept override; +}; + +class file_status { +public: + file_status() noexcept; + explicit file_status(file_type ft, + perms prms = perms::unknown) noexcept; + + file_status(const file_status& other) noexcept = default; + file_status(file_status&& other) noexcept = default; + ~file_status(); + + file_status& operator=(const file_status& other) noexcept = default; + file_status& operator=(file_status&& other) noexcept = default; + + void type(file_type ft) noexcept; + void permissions(perms prms) noexcept; + + file_type type() const noexcept; + perms permissions() const noexcept; + +}; + +bool operator==(const file_status& lhs, const file_status& rhs) noexcept; + +using file_time_type = chrono::time_point; + +class directory_entry { +public: + // constructors and destructor + directory_entry() noexcept = default; + directory_entry(const directory_entry& other) = default; + directory_entry(directory_entry&& other) noexcept = default; + + explicit directory_entry(const filesystem::path& p); + + directory_entry(const filesystem::path& p, error_code& ec); + ~directory_entry(); + + directory_entry& operator=(const directory_entry&) = default; + directory_entry& operator=(directory_entry&&) noexcept = default; + + void assign(const filesystem::path& p); + void assign(const filesystem::path& p, error_code& ec); + void replace_filename(const filesystem::path& p); + void replace_filename(const filesystem::path& p, error_code& ec); + void refresh(); + void refresh(error_code& ec) noexcept; + + const filesystem::path& path() const noexcept; + operator const filesystem::path&() const noexcept; + bool exists() const; + bool exists(error_code& ec) const noexcept; + bool is_block_file() const; + bool is_block_file(error_code& ec) const noexcept; + bool is_character_file() const; + bool is_character_file(error_code& ec) const noexcept; + bool is_directory() const; + bool is_directory(error_code& ec) const noexcept; + bool is_fifo() const; + bool is_fifo(error_code& ec) const noexcept; + bool is_other() const; + bool is_other(error_code& ec) const noexcept; + bool is_regular_file() const; + bool is_regular_file(error_code& ec) const noexcept; + bool is_socket() const; + bool is_socket(error_code& ec) const noexcept; + bool is_symlink() const; + bool is_symlink(error_code& ec) const noexcept; + uintmax_t file_size() const; + uintmax_t file_size(error_code& ec) const noexcept; + uintmax_t hard_link_count() const; + uintmax_t hard_link_count(error_code& ec) const noexcept; + file_time_type last_write_time() const; + file_time_type last_write_time(error_code& ec) const noexcept; + file_status status() const; + file_status status(error_code& ec) const noexcept; + file_status symlink_status() const; + file_status symlink_status(error_code& ec) const noexcept; + + bool operator==(const directory_entry& rhs) const noexcept; + auto operator<=>const directory_entry& rhs) const noexcept = default; +}; + +template +basic_ostream& + operator<<(basic_ostream& os, const directory_entry& d); + + +class directory_iterator { +public: + using iterator_category = input_iterator_tag; + using value_type = directory_entry; + using difference_type = ptrdiff_t; + using pointer = const directory_entry*; + using reference = const directory_entry&; + + directory_iterator() noexcept; + explicit directory_iterator(const path& p); + directory_iterator(const path& p, directory_options options); + directory_iterator(const path& p, error_code& ec); + directory_iterator(const path& p, directory_options options, error_code& ec); + directory_iterator(const directory_iterator& other); + directory_iterator(directory_iterator&& other) noexcept; + ~directory_iterator(); + + directory_iterator& operator=(const directory_iterator& other); + directory_iterator& operator=(directory_iterator&& other) noexcept; + + const directory_entry& operator*() const; + const directory_entry* operator->() const; + directory_iterator& operator++(); + directory_iterator& increment(error_code& ec); +}; + +directory_iterator begin(directory_iterator iter) noexcept; +directory_iterator end(directory_iterator) noexcept; + +class recursive_directory_iterator { +public: + using iterator_category = input_iterator_tag; + using value_type = directory_entry; + using difference_type = ptrdiff_t; + using pointer = const directory_entry*; + using reference = const directory_entry&; + + recursive_directory_iterator() noexcept; + explicit recursive_directory_iterator(const path& p); + recursive_directory_iterator(const path& p, directory_options options); + recursive_directory_iterator(const path& p, directory_options options, error_code& ec); + recursive_directory_iterator(const path& p, error_code& ec); + recursive_directory_iterator(const recursive_directory_iterator& other); + recursive_directory_iterator(recursive_directory_iterator&& other) noexcept; + ~recursive_directory_iterator(); + + recursive_directory_iterator& operator=(const recursive_directory_iterator& other); + recursive_directory_iterator& operator=(recursive_directory_iterator&& other) noexcept; + + directory_options options() const; + int depth() const; + bool recursion_pending() const; + + const directory_entry& operator*() const; + const directory_entry* operator->() const; + + recursive_directory_iterator& operator++(); + recursive_directory_iterator& increment(error_code& ec); + + void pop(); + void pop(error_code& ec); + void disable_recursion_pending(); +}; + +recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept; +recursive_directory_iterator end(recursive_directory_iterator) noexcept; + +struct space_info { + uintmax_t capacity; + uintmax_t free; + uintmax_t available; + friend bool operator==(const space_info&, const space_info&); +}; + +path absolute(const path& p); +path absolute(const path& p, error_code& ec); + +path canonical(const path& p); +path canonical(const path& p, error_code& ec); + +void copy(const path& from, const path& to); +void copy(const path& from, const path& to, error_code& ec); +void copy(const path& from, const path& to, copy_options options); +void copy(const path& from, const path& to, copy_options options, + error_code& ec); + +bool copy_file(const path& from, const path& to); +bool copy_file(const path& from, const path& to, error_code& ec); +bool copy_file(const path& from, const path& to, copy_options option); +bool copy_file(const path& from, const path& to, copy_options option, + error_code& ec); + +void copy_symlink(const path& existing_symlink, const path& new_symlink); +void copy_symlink(const path& existing_symlink, const path& new_symlink, + error_code& ec) noexcept; + +bool create_directories(const path& p); +bool create_directories(const path& p, error_code& ec); + +bool create_directory(const path& p); +bool create_directory(const path& p, error_code& ec) noexcept; + +bool create_directory(const path& p, const path& attributes); +bool create_directory(const path& p, const path& attributes, + error_code& ec) noexcept; + +void create_directory_symlink(const path& to, const path& new_symlink); +void create_directory_symlink(const path& to, const path& new_symlink, + error_code& ec) noexcept; + +void create_hard_link(const path& to, const path& new_hard_link); +void create_hard_link(const path& to, const path& new_hard_link, + error_code& ec) noexcept; + +void create_symlink(const path& to, const path& new_symlink); +void create_symlink(const path& to, const path& new_symlink, + error_code& ec) noexcept; + +path current_path(); +path current_path(error_code& ec); +void current_path(const path& p); +void current_path(const path& p, error_code& ec) noexcept; + +bool equivalent(const path& p1, const path& p2); +bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept; + +bool exists(file_status s) noexcept; +bool exists(const path& p); +bool exists(const path& p, error_code& ec) noexcept; + +uintmax_t file_size(const path& p); +uintmax_t file_size(const path& p, error_code& ec) noexcept; + +uintmax_t hard_link_count(const path& p); +uintmax_t hard_link_count(const path& p, error_code& ec) noexcept; + +bool is_block_file(file_status s) noexcept; +bool is_block_file(const path& p); +bool is_block_file(const path& p, error_code& ec) noexcept; + +bool is_character_file(file_status s) noexcept; +bool is_character_file(const path& p); +bool is_character_file(const path& p, error_code& ec) noexcept; + +bool is_directory(file_status s) noexcept; +bool is_directory(const path& p); +bool is_directory(const path& p, error_code& ec) noexcept; + +bool is_empty(const path& p); +bool is_empty(const path& p, error_code& ec); + +bool is_fifo(file_status s) noexcept; +bool is_fifo(const path& p); +bool is_fifo(const path& p, error_code& ec) noexcept; + +bool is_other(file_status s) noexcept; +bool is_other(const path& p); +bool is_other(const path& p, error_code& ec) noexcept; + +bool is_regular_file(file_status s) noexcept; +bool is_regular_file(const path& p); +bool is_regular_file(const path& p, error_code& ec) noexcept; + +bool is_socket(file_status s) noexcept; +bool is_socket(const path& p); +bool is_socket(const path& p, error_code& ec) noexcept; + +bool is_symlink(file_status s) noexcept; +bool is_symlink(const path& p); +bool is_symlink(const path& p, error_code& ec) noexcept; + +file_time_type last_write_time(const path& p); +file_time_type last_write_time(const path& p, error_code& ec) noexcept; +void last_write_time(const path& p, file_time_type new_time); +void last_write_time(const path& p, file_time_type new_time, + error_code& ec) noexcept; + +void permissions(const path& p, perms prms, perm_options opts=perm_options::replace); +void permissions(const path& p, perms prms, error_code& ec) noexcept; +void permissions(const path& p, perms prms, perm_options opts, error_code& ec); + +path proximate(const path& p, error_code& ec); +path proximate(const path& p, const path& base = current_path()); +path proximate(const path& p, const path& base, error_code& ec); + +path read_symlink(const path& p); +path read_symlink(const path& p, error_code& ec); + +path relative(const path& p, error_code& ec); +path relative(const path& p, const path& base = current_path()); +path relative(const path& p, const path& base, error_code& ec); + +bool remove(const path& p); +bool remove(const path& p, error_code& ec) noexcept; + +uintmax_t remove_all(const path& p); +uintmax_t remove_all(const path& p, error_code& ec); + +void rename(const path& from, const path& to); +void rename(const path& from, const path& to, error_code& ec) noexcept; + +void resize_file(const path& p, uintmax_t size); +void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept; + +space_info space(const path& p); +space_info space(const path& p, error_code& ec) noexcept; + +file_status status(const path& p); +file_status status(const path& p, error_code& ec) noexcept; + +bool status_known(file_status s) noexcept; + +file_status symlink_status(const path& p); +file_status symlink_status(const path& p, error_code& ec) noexcept; + +path temp_directory_path(); +path temp_directory_path(error_code& ec); + +path weakly_canonical(const path& p); +path weakly_canonical(const path& p, error_code& ec); + +} // namespace std::filesystem + +#endif // if CPPREFERENCE_STDVER >= 2017 + +#endif // CPPREFERENCE_FILESYSTEM_H diff --git a/headers/forward_list b/headers/forward_list index 38154dd48..ce9688232 100644 --- a/headers/forward_list +++ b/headers/forward_list @@ -129,8 +129,13 @@ public: void push_front(const T& value); void push_front(T&& value); +#if CPPREFERENCE_STDVER >= 2017 + template + reference emplace_front(Args&& ... args); +#else template void emplace_front(Args&& ... args); +#endif void pop_front(); diff --git a/headers/fstream b/headers/fstream index 13c31e180..406852981 100644 --- a/headers/fstream +++ b/headers/fstream @@ -16,20 +16,30 @@ #ifndef CPPREFERENCE_FSTREAM_H #define CPPREFERENCE_FSTREAM_H +#include +#include + namespace std { -template < +template< class CharT, - class Traits = std::char_traits - > class basic_filebuf : public std::basic_streambuf { + class Traits /* = std::char_traits */ +> class basic_filebuf : public basic_streambuf { + public: + typedef CharT char_type; + typedef Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + basic_filebuf(); #if CPPREFERENCE_STDVER>= 2011 - basic_filebuf(const std::basic_filebuf& rhs) = delete; - basic_filebuf(std::basic_filebuf&& rhs); - std::basic_filebuf& operator=(std::basic_filebuf&& rhs); - std::basic_filebuf& operator=(const std::basic_filebuf& rhs) = delete; - void swap(std::basic_filebuf& rhs); + basic_filebuf(const basic_filebuf& rhs) = delete; + basic_filebuf(basic_filebuf&& rhs); + basic_filebuf& operator=(basic_filebuf&& rhs); + basic_filebuf& operator=(const basic_filebuf& rhs) = delete; + void swap(basic_filebuf& rhs); #endif virtual ~basic_filebuf(); @@ -43,8 +53,8 @@ protected: virtual streamsize showmanyc(); virtual int_type underflow(); virtual int_type uflow(); - virtual int_type pbackfail(int_type c = Traits_type::eof()); - virtual int_type overflow(int_type c = Traits_type::eof()); + virtual int_type pbackfail(int_type c = traits_type::eof()); + virtual int_type overflow(int_type c = traits_type::eof()); virtual basic_streambuf* setbuf(char_type* s, streamsize n); virtual pos_type seekoff(off_type off, ios_base::seekdir dir, ios_base::openmode which = ios_base::in | ios_base::out); @@ -59,9 +69,15 @@ typedef basic_filebuf wfilebuf; template < class CharT, - class Traits = std::char_traits - > class basic_fstream : public std::basic_iostream { + class Traits /* = std::char_traits */ +> class basic_fstream : public std::basic_iostream { public: + typedef CharT char_type; + typedef Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + basic_fstream(); explicit basic_fstream(const char* filename, ios_base::openmode mode = ios_base::in | ios_base::out); @@ -100,8 +116,8 @@ typedef basic_fstream wfstream; template < class CharT, - class Traits = std::char_traits - > class basic_ifstream : public std::basic_istream { + class Traits /* = std::char_traits */ +> class basic_ifstream : public std::basic_istream { public: basic_ifstream(); explicit basic_ifstream(const char* filename, @@ -141,8 +157,8 @@ typedef basic_ifstream wifstream; template < class CharT, - class Traits = std::char_traits - > class basic_ofstream : public std::basic_ostream { + class Traits /* = std::char_traits */ +> class basic_ofstream : public std::basic_ostream { public: basic_ofstream(); explicit basic_ofstream(const char* filename, diff --git a/headers/functional b/headers/functional index e3cbb5b9a..bb650b49b 100644 --- a/headers/functional +++ b/headers/functional @@ -16,9 +16,21 @@ #ifndef CPPREFERENCE_FUNCTIONAL_H #define CPPREFERENCE_FUNCTIONAL_H +#include // for exception +#include // for allocator_arg_t +#include +#include + namespace std { #if CPPREFERENCE_STDVER >= 2011 + +template +class function; + +template +class reference_wrapper; + template class function { public: @@ -27,25 +39,29 @@ public: function(std::nullptr_t); function(const function& other); function(function&& other); - template - function(F f); - template + + template + function(F f) { (void) f; } + +#if CPPREFERENCE_STDVER < 2017 + template function(std::allocator_arg_t, const Alloc& alloc); - template + template function(std::allocator_arg_t, const Alloc& alloc, std::nullptr_t); - template + template function(std::allocator_arg_t, const Alloc& alloc, const function& other); - template + template function(std::allocator_arg_t, const Alloc& alloc, function&& other); - template + template function(std::allocator_arg_t, const Alloc& alloc, F f); +#endif ~function(); @@ -53,43 +69,43 @@ public: function& operator=(function&& other); function& operator=(std::nullptr_t); - template + template function& operator=(F&& f); - template + template function& operator=(std::reference_wrapper f); void swap(function& other); - template + template void assign(F&& f, const Alloc& alloc); explicit operator bool() const; - R operator()(ArgTypes... args) const; + R operator()(Args... args) const; const std::type_info& target_type() const; - template + template T* target(); - template + template const T* target() const; }; template void swap(function& lhs, function& rhs); -template +template bool operator==(const std::function& f, std::nullptr_t); -template +template bool operator==(std::nullptr_t, const std::function& f); -template +template bool operator!=(const std::function& f, std::nullptr_t); -template +template bool operator!=(std::nullptr_t, const std::function& f); class bad_function_call : public std::exception { @@ -99,25 +115,25 @@ public: // SIMPLIFIED: actual result is unspecified, std::function is only for // providing return type -template +template std::function mem_fn(R T::* pm); -template +template std::function bind(F&& f, Args&& ... args); -template +template std::function bind(F&& f, Args&& ... args); #if CPPREFERENCE_STDVER >= 2017 template -std::result_of_t < F&& (ArgTypes&& ...) > invoke(F&& f, ArgTypes&& ... args); +std::result_of_t invoke(F&& f, ArgTypes&&... args); #endif // SIMPLIFIED: the inherited type is simplified -template +template struct is_bind_expression : std::integral_constant {}; -template +template struct is_placeholder : std::integral_constant {}; namespace placeholders { // SIMPLIFIED: the actual type is unspecified @@ -142,8 +158,8 @@ public: typedef void first_argument_type; typedef void second_argument_type; - reference_wrapper(T& x); - reference_wrapper(T&& x) = delete; + template + reference_wrapper(U&& x); reference_wrapper(const reference_wrapper& other); reference_wrapper& operator=(const reference_wrapper& other); @@ -151,24 +167,24 @@ public: operator T& () const; T& get() const; - template - typename std::result_of < T& (ArgTypes&& ...) >::type + template + typename std::result_of::type operator()(ArgTypes&& ... args) const; // only if T is function }; -template +template std::reference_wrapper ref(T& t); -template +template std::reference_wrapper ref(std::reference_wrapper t); template void ref(const T&&) = delete; -template +template std::reference_wrapper cref(const T& t); -template +template std::reference_wrapper cref(std::reference_wrapper t); template @@ -176,7 +192,11 @@ void cref(const T&&) = delete; #endif // CPPREFERENCE_STDVER >= 2011 +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct plus { typedef T result_type; typedef T first_argument_type; @@ -184,7 +204,11 @@ struct plus { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct minus { typedef T result_type; typedef T first_argument_type; @@ -192,7 +216,11 @@ struct minus { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct multiplies { typedef T result_type; typedef T first_argument_type; @@ -200,7 +228,11 @@ struct multiplies { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct divides { typedef T result_type; typedef T first_argument_type; @@ -208,7 +240,11 @@ struct divides { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct modulus { typedef T result_type; typedef T first_argument_type; @@ -216,14 +252,22 @@ struct modulus { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct negate { typedef T result_type; typedef T argument_type; T operator()(const T& arg) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct equal_to { typedef bool result_type; typedef T first_argument_type; @@ -231,7 +275,11 @@ struct equal_to { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct not_equal_to { typedef bool result_type; typedef T first_argument_type; @@ -239,7 +287,11 @@ struct not_equal_to { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct greater { typedef bool result_type; typedef T first_argument_type; @@ -247,7 +299,11 @@ struct greater { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct less { typedef bool result_type; typedef T first_argument_type; @@ -255,7 +311,11 @@ struct less { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct greater_equal { typedef bool result_type; typedef T first_argument_type; @@ -263,7 +323,11 @@ struct greater_equal { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct less_equal { typedef bool result_type; typedef T first_argument_type; @@ -271,7 +335,11 @@ struct less_equal { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct logical_and { typedef bool result_type; typedef T first_argument_type; @@ -279,7 +347,11 @@ struct logical_and { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct logical_or { typedef bool result_type; typedef T first_argument_type; @@ -287,14 +359,22 @@ struct logical_or { bool operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct logical_not { typedef bool result_type; typedef T argument_type; bool operator()(const T& arg) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct bit_and { typedef T result_type; typedef T first_argument_type; @@ -302,7 +382,11 @@ struct bit_and { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct bit_or { typedef T result_type; typedef T first_argument_type; @@ -310,7 +394,11 @@ struct bit_or { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct bit_xor { typedef T result_type; typedef T first_argument_type; @@ -318,14 +406,19 @@ struct bit_xor { T operator()(const T& lhs, const T& rhs) const; }; +#if CPPREFERENCE_STDVER >= 2014 template +#else +template +#endif struct bit_not { typedef T result_type; typedef T argument_type; T operator()(const T& arg) const; }; -template +#if CPPREFERENCE_STDVER <= 2020 +template struct unary_negate { typedef bool result_type; typedef typename Predicate::argument_type argument_type; @@ -334,24 +427,26 @@ struct unary_negate { result_type operator()(argument_type const& x) const; }; -template +template struct binary_negate { typedef bool result_type; typedef typename Predicate::first_argument_type first_argument_type; typedef typename Predicate::second_argument_type second_argument_type; explicit binary_negate(const Predicate& pred); - result_type operator()(const T& lhs, const T& rhs) const; + result_type operator()(const first_argument_type& lhs, + const second_argument_type& rhs) const; }; -template +template std::unary_negate not1(const Predicate& pred); -template +template std::binary_negate not2(const Predicate& pred); +#endif #if CPPREFERENCE_STDVER >= 2011 -template +template struct hash { typedef Key argument_type; typedef std::size_t result_type; diff --git a/headers/future b/headers/future index c69d339d8..c74f6c722 100644 --- a/headers/future +++ b/headers/future @@ -17,10 +17,21 @@ #define CPPREFERENCE_FUTURE_H #if CPPREFERENCE_STDVER>= 2011 +#include +#include // for allocator_arg_t #include +#include // for error_code namespace std { +template +class future; + +template +class shared_future; + +enum class future_status; + template class promise { // SIMPLIFIED: removed R& and void specializations public: @@ -37,7 +48,7 @@ public: void swap(promise& other); - std::future get_future(); + future get_future(); void set_value(const R& value); void set_value(R&& value); @@ -54,8 +65,11 @@ public: template void swap(promise& lhs, promise& rhs); -template -class packaged_task { +template +class packaged_task; + +template +class packaged_task { public: packaged_task(); @@ -104,8 +118,8 @@ public: std::shared_future share(); T get(); // member only of generic specialization - T& get(); // member only of T& specialization - void get(); // member only of void specialization + // T& get(); // member only of T& specialization + // void get(); // member only of void specialization bool valid() const; @@ -132,8 +146,8 @@ public: shared_future& operator=(shared_future&& other); T get(); // member only of generic specialization - T& get(); // member only of T& specialization - void get(); // member only of void specialization + // T& get(); // member only of T& specialization + // void get(); // member only of void specialization bool valid() const; @@ -170,13 +184,33 @@ public: const std::error_code& code() const; }; +#if CPPREFERENCE_STDVER >= 2020 +template +[[nodiscard]] +std::future> + async(Function&& f, Args&& ... args); + +template +[[nodiscard]] +std::future> + async(std::launch policy, Function&& f, Args&& ... args); +#elif CPPREFERENCE_STDVER >= 2017 +template +std::future> + async(Function&& f, Args&& ... args); + +template +std::future> + async(std::launch policy, Function&& f, Args&& ... args); +#else template std::future::type> -async(Function&& f, Args&& ... args); + async(Function&& f, Args&& ... args); template std::future::type> -async(std::launch policy, Function&& f, Args&& ... args); + async(std::launch policy, Function&& f, Args&& ... args); +#endif const std::error_category& future_category(); diff --git a/headers/initializer_list b/headers/initializer_list index 41bc03ed0..30ce679b8 100644 --- a/headers/initializer_list +++ b/headers/initializer_list @@ -18,6 +18,8 @@ #if CPPREFERENCE_STDVER>= 2011 +#include // for size_t + namespace std { template @@ -31,15 +33,28 @@ public: typedef const T* iterator; typedef const T* const_iterator; +#if CPPREFERENCE_STDVER >= 2014 + constexpr initializer_list(); + + constexpr size_t size() const; + constexpr const T* begin() const; + constexpr const T* end() const; +#else initializer_list(); size_t size() const; const T* begin() const; const T* end() const; +#endif }; +#if CPPREFERENCE_STDVER >= 2014 +template constexpr const T* begin(initializer_list il); +template constexpr const T* end(initializer_list il); +#else template const T* begin(initializer_list il); template const T* end(initializer_list il); +#endif } // namespace std diff --git a/headers/iomanip b/headers/iomanip index 67ffa8aed..a88e9cf98 100644 --- a/headers/iomanip +++ b/headers/iomanip @@ -16,7 +16,8 @@ #ifndef CPPREFERENCE_IOMANIP_H #define CPPREFERENCE_IOMANIP_H -#include +#include +#include // for tm namespace std { diff --git a/headers/ios b/headers/ios index 174969654..615812da9 100644 --- a/headers/ios +++ b/headers/ios @@ -19,13 +19,24 @@ #if CPPREFERENCE_STDVER>= 2011 #include #endif +#include +#include namespace std { +typedef int __impl_defined_type; +static const __impl_defined_type __impl_defined_value = 0; + typedef int streamoff; typedef int streamsize; template class fpos; +#if CPPREFERENCE_STDVER>= 2011 +enum class io_errc { + stream +}; +#endif + class ios_base { private: ios_base(const ios_base& other); @@ -51,47 +62,47 @@ public: class Init; - typedef int openmode; // actually impl-defined - static constexpr openmode app; - static constexpr openmode binary; - static constexpr openmode in; - static constexpr openmode out; - static constexpr openmode trunc; - static constexpr openmode ate; - - typedef int fmtflags; // actually impl-defined - static constexpr fmtflags dec; - static constexpr fmtflags oct; - static constexpr fmtflags hex; - static constexpr fmtflags basefield; - - static constexpr fmtflags left; - static constexpr fmtflags right; - static constexpr fmtflags internal; - static constexpr fmtflags adjustfield; - - static constexpr fmtflags scientific; - static constexpr fmtflags fixed; - static constexpr fmtflags floatfield; - - static constexpr fmtflags boolalpha; - static constexpr fmtflags showbase; - static constexpr fmtflags showpoint; - static constexpr fmtflags showpos; - static constexpr fmtflags skipws; - static constexpr fmtflags unitbuf; - static constexpr fmtflags uppercase; - - typedef int iostate; // actually impl-defined - static constexpr iostate goodbit; - static constexpr iostate badbit; - static constexpr iostate failbit; - static constexpr iostate eofbit; - - typedef int seekdir; // actually impl-defined - static constexpr seekdir beg; - static constexpr seekdir end; - static constexpr seekdir cur; + typedef __impl_defined_type openmode; + static constexpr openmode app = __impl_defined_value; + static constexpr openmode binary = __impl_defined_value; + static constexpr openmode in = __impl_defined_value; + static constexpr openmode out = __impl_defined_value; + static constexpr openmode trunc = __impl_defined_value; + static constexpr openmode ate = __impl_defined_value; + + typedef __impl_defined_type fmtflags; + static constexpr fmtflags dec = __impl_defined_value; + static constexpr fmtflags oct = __impl_defined_value; + static constexpr fmtflags hex = __impl_defined_value; + static constexpr fmtflags basefield = __impl_defined_value; + + static constexpr fmtflags left = __impl_defined_value; + static constexpr fmtflags right = __impl_defined_value; + static constexpr fmtflags internal = __impl_defined_value; + static constexpr fmtflags adjustfield = __impl_defined_value; + + static constexpr fmtflags scientific = __impl_defined_value; + static constexpr fmtflags fixed = __impl_defined_value; + static constexpr fmtflags floatfield = __impl_defined_value; + + static constexpr fmtflags boolalpha = __impl_defined_value; + static constexpr fmtflags showbase = __impl_defined_value; + static constexpr fmtflags showpoint = __impl_defined_value; + static constexpr fmtflags showpos = __impl_defined_value; + static constexpr fmtflags skipws = __impl_defined_value; + static constexpr fmtflags unitbuf = __impl_defined_value; + static constexpr fmtflags uppercase = __impl_defined_value; + + typedef __impl_defined_type iostate; + static constexpr iostate goodbit = __impl_defined_value; + static constexpr iostate badbit = __impl_defined_value; + static constexpr iostate failbit = __impl_defined_value; + static constexpr iostate eofbit = __impl_defined_value; + + typedef __impl_defined_type seekdir; + static constexpr seekdir beg = __impl_defined_value; + static constexpr seekdir end = __impl_defined_value; + static constexpr seekdir cur = __impl_defined_value; enum event { erase_event, @@ -124,7 +135,7 @@ public: }; template> + class Traits /* = std::char_traits */> class basic_ios : public ios_base { public: typedef CharT char_type; @@ -171,9 +182,6 @@ public: std::basic_ostream* tie() const; std::basic_ostream* tie(std::basic_ostream* str); - char narrow(char_type c, char dfault) const; - char_type widen(char c) const; - protected: basic_ios(); void init(std::basic_streambuf* sb); @@ -221,10 +229,6 @@ ios_base& hexfloat(ios_base& str); ios_base& defaultfloat(ios_base& str); #if CPPREFERENCE_STDVER>= 2011 -enum class io_errc { - stream -}; - std::error_code make_error_code(std::io_errc e); std::error_condition make_error_condition(std::io_errc e); const std::error_category& iostream_category(); diff --git a/headers/iosfwd b/headers/iosfwd index a22df584e..1f7c14bc8 100644 --- a/headers/iosfwd +++ b/headers/iosfwd @@ -16,12 +16,16 @@ #ifndef CPPREFERENCE_IOSFWD_H #define CPPREFERENCE_IOSFWD_H +#include // for mbstate_t + namespace std { template struct char_traits; template class allocator; +typedef int streamoff; + class ios_base; template> class basic_ios; @@ -80,9 +84,10 @@ typedef basic_istringstream wistringstream; typedef basic_ostringstream wostringstream; typedef basic_stringstream wstringstream; -template class fpos; -typedef fpos::state_type> streampos; -typedef fpos::state_type> wstreampos; +template class fpos; + // state type in below typedefs is actually impl-defined type char_traits::state_type +typedef fpos streampos; +typedef fpos wstreampos; } // namespace std diff --git a/headers/istream b/headers/istream index 8fb7ecc1e..36762cf3c 100644 --- a/headers/istream +++ b/headers/istream @@ -16,13 +16,22 @@ #ifndef CPPREFERENCE_ISTREAM_H #define CPPREFERENCE_ISTREAM_H +#include +#include + namespace std { template < class CharT, - class Traits = std::char_traits + class Traits /* = std::char_traits */ > class basic_istream : virtual public std::basic_ios { public: + typedef CharT char_type; + typedef Traits traits_type; + typedef typename Traits::int_type int_type; + typedef typename Traits::pos_type pos_type; + typedef typename Traits::off_type off_type; + explicit basic_istream(std::basic_streambuf* sb); virtual ~basic_istream(); @@ -41,21 +50,17 @@ public: basic_istream& operator>>(long double& value); basic_istream& operator>>(bool& value); basic_istream& operator>>(void*& value); - basic_istream& operator>>(basic_istream& st, - std::ios_base & (*func)(std::ios_base&)); - basic_istream& operator>>(basic_istream& st, - std::basic_ios& (*func)(std::basic_ios&)); - basic_istream& operator>>(basic_istream& st, - std::basic_istream & (*func)(std::basic_istream&)); - basic_istream& operator>>(basic_istream& st, - std::basic_streambuf* sb); + basic_istream& operator>>(std::ios_base & (*func)(std::ios_base&)); + basic_istream& operator>>(std::basic_ios& (*func)(std::basic_ios&)); + basic_istream& operator>>(basic_istream & (*func)(basic_istream&)); + basic_istream& operator>>(std::basic_streambuf* sb); int_type get(); basic_istream& get(char_type& ch); basic_istream& get(char_type* s, std::streamsize count); basic_istream& get(char_type* s, std::streamsize count, char_type delim); - basic_istream& get(basic_streambuf& strbuf); - basic_istream& get(basic_streambuf& strbuf, char_type delim); + basic_istream& get(basic_streambuf& strbuf); + basic_istream& get(basic_streambuf& strbuf, char_type delim); int_type peek(); basic_istream& unget(); @@ -100,8 +105,8 @@ extern wistream wcin; template < class CharT, - class Traits = std::char_traits - > class basic_iostream : public std::basic_istream, + class Traits /* = std::char_traits */ +> class basic_iostream : public std::basic_istream, public basic_ostream { public: explicit basic_iostream(std::basic_streambuf* sb); diff --git a/headers/iterator b/headers/iterator index 6ca93f058..add673bd6 100644 --- a/headers/iterator +++ b/headers/iterator @@ -17,9 +17,17 @@ #define CPPREFERENCE_ITERATOR_H #include // for size_t, ptrdiff_t +#include // char_traits +#include namespace std { +struct input_iterator_tag { }; +struct output_iterator_tag { }; +struct forward_iterator_tag : public input_iterator_tag { }; +struct bidirectional_iterator_tag : public forward_iterator_tag { }; +struct random_access_iterator_tag : public bidirectional_iterator_tag { }; + // SIMPLIFIED: template specializations are not supported, so the typedefs use // the T* specialization template @@ -39,11 +47,14 @@ struct iterator_traits { #endif }; -struct input_iterator_tag { }; -struct output_iterator_tag { }; -struct forward_iterator_tag : public input_iterator_tag { }; -struct bidirectional_iterator_tag : public forward_iterator_tag { }; -struct random_access_iterator_tag : public bidirectional_iterator_tag { }; +template +struct iterator_traits { + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef random_access_iterator_tag iterator_category; +}; template @@ -97,36 +108,36 @@ protected: Iterator current; }; -template +template bool operator==(const reverse_iterator& lhs, const reverse_iterator& rhs); -template +template bool operator!=(const reverse_iterator& lhs, const reverse_iterator& rhs); -template +template bool operator<(const reverse_iterator& lhs, const reverse_iterator& rhs); -template +template bool operator<=(const reverse_iterator& lhs, const reverse_iterator& rhs); -template +template bool operator>(const reverse_iterator& lhs, const reverse_iterator& rhs); -template +template bool operator>=(const reverse_iterator& lhs, const reverse_iterator& rhs); -template +template reverse_iterator operator+(typename reverse_iterator::difference_type n, const reverse_iterator& it); -template +template typename reverse_iterator::difference_type operator-(const reverse_iterator& lhs, const reverse_iterator& rhs); @@ -137,11 +148,14 @@ class move_iterator { public: typedef Iterator iterator_type; typedef Iterator pointer; - typedef value_type&& reference; #if CPPREFERENCE_SIMPLIFY_TYPEDEFS + typedef typename Iterator::value_type value_type; + typedef value_type&& reference; typedef typename ptrdiff_t difference_type; typedef typename Iterator::iterator_category iterator_category; #else + typedef typename iterator_traits::value_type value_type; + typedef value_type&& reference; typedef typename iterator_traits::difference_type difference_type; typedef typename iterator_traits::iterator_category iterator_category; #endif @@ -169,36 +183,36 @@ public: }; -template +template bool operator==(const move_iterator& lhs, const move_iterator& rhs); -template +template bool operator!=(const move_iterator& lhs, const move_iterator& rhs); -template +template bool operator<(const move_iterator& lhs, const move_iterator& rhs); -template +template bool operator<=(const move_iterator& lhs, const move_iterator& rhs); -template +template bool operator>(const move_iterator& lhs, const move_iterator& rhs); -template +template bool operator>=(const move_iterator& lhs, const move_iterator& rhs); -template +template move_iterator operator+(typename move_iterator::difference_type n, const move_iterator& it); -template +template typename move_iterator::difference_type operator-(const move_iterator& lhs, const move_iterator& rhs); @@ -290,13 +304,13 @@ public: insert_iterator& operator++(int); protected: Container* container; - Container::iterator iter; + typename Container::iterator iter; }; template, - class Distance = std::ptrdiff_t > + class Distance = std::ptrdiff_t> class istream_iterator { // SIMPLIFIED: does not inherit iterator public: typedef CharT char_type; @@ -322,11 +336,11 @@ public: istream_iterator operator++(int); }; -template +template bool operator==(const istream_iterator& lhs, const istream_iterator& rhs); -template +template bool operator!=(const istream_iterator& lhs, const istream_iterator& rhs); @@ -356,16 +370,16 @@ public: ostream_iterator& operator++(int); }; -template +template bool operator==(const ostream_iterator& lhs, const ostream_iterator& rhs); -template +template bool operator!=(const ostream_iterator& lhs, const ostream_iterator& rhs); -template > +template*/> class istreambuf_iterator { // SIMPLIFIED: does not inherit iterator public: typedef CharT char_type; @@ -378,10 +392,10 @@ public: typedef std::basic_streambuf streambuf_type; typedef std::basic_istream istream_type; - typedef T value_type; - typedef Distance difference_type; - typedef const T* pointer; - typedef const T& reference; + typedef CharT value_type; + typedef typename Traits::off_type difference_type; + typedef const CharT* pointer; // actually unspecified + typedef const CharT& reference; typedef input_iterator_tag iterator_category; istreambuf_iterator(); @@ -399,16 +413,16 @@ public: bool equal(const istreambuf_iterator& it) const; }; -template +template bool operator==(const istreambuf_iterator& lhs, const istreambuf_iterator& rhs); -template +template bool operator!=(const istreambuf_iterator& lhs, const istreambuf_iterator& rhs); template > + class Traits /* = std::char_traits*/ > class ostreambuf_iterator { // SIMPLIFIED: does not inherit iterator public: typedef CharT char_type; @@ -432,91 +446,126 @@ public: bool failed() const; }; -#if CPPREFERENCE_STDVER >= 2011 && CPPREFERENCE_STDVER <2014 -template -std::move_iterator make_move_iterator(const Iterator& i); +#if CPPREFERENCE_STDVER >= 2017 +template +constexpr std::move_iterator make_move_iterator(Iterator i); + +template +constexpr std::reverse_iterator make_reverse_iterator(Iterator i); #elif CPPREFERENCE_STDVER >= 2014 -template +template std::move_iterator make_move_iterator(Iterator i); template std::reverse_iterator make_reverse_iterator(Iterator i); +#elif CPPREFERENCE_STDVER >= 2011 +template +std::move_iterator make_move_iterator(const Iterator& i); #endif -template +template std::front_insert_iterator front_inserter(Container& c); -template +template std::back_insert_iterator back_inserter(Container& c); -template +template std::insert_iterator inserter(Container& c, typename Container::iterator i); template void advance(InputIt& it, Distance n); -template +template typename std::iterator_traits::difference_type distance(InputIt first, InputIt last); #if CPPREFERENCE_STDVER >= 2011 -template +template ForwardIt next(ForwardIt it, typename std::iterator_traits::difference_type n = 1); -template +template BidirIt prev(BidirIt it, typename std::iterator_traits::difference_type n = 1); +#endif + +#if CPPREFERENCE_STDVER >= 2017 +template +constexpr auto begin(C& c) -> decltype(c.begin()); + +template +constexpr auto begin(const C& c) -> decltype(c.begin()); + +template +constexpr auto end(C& c) -> decltype(c.end()); -template +template +constexpr auto end(const C& c) -> decltype(c.end()); + +#elif CPPREFERENCE_STDVER >= 2011 +template auto begin(C& c) -> decltype(c.begin()); -template +template auto begin(const C& c) -> decltype(c.begin()); -template -T* begin(T(&array)[N]); - -template +template auto end(C& c) -> decltype(c.end()); -template +template auto end(const C& c) -> decltype(c.end()); +#endif -template -T* end(T(&array)[N]); +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr T* begin(T(&array)[N]); + +template +constexpr T* end(T(&array)[N]); +#elif CPPREFERENCE_STDVER >= 2011 +template +T* begin(T(&array)[N]); + +template +T* end(T(&array)[N]); #endif -#if CPPREFERENCE_STDVER >= 2014 -template +#if CPPREFERENCE_STDVER >= 2014 +template constexpr auto cbegin(const C& c) -> decltype(std::begin(c)); -template +template constexpr auto cend(const C& c) -> decltype(std::end(c)); -template +template auto rbegin(C& c) -> decltype(c.rbegin()); -template +template auto rbegin(const C& c) -> decltype(c.rbegin()); -template +template reverse_iterator rbegin(T(&array)[N]); -template +template +reverse_iterator rbegin(std::initializer_list il); + +template auto crbegin(const C& c) -> decltype(std::rbegin(c)); -template +template auto rend(C& c) -> decltype(c.rend()); -template +template auto rend(const C& c) -> decltype(c.rend()); -template +template reverse_iterator rend(T(&array)[N]); -template +template +reverse_iterator rend(std::initializer_list il); + +template auto crend(const C& c) -> decltype(std::rend(c)); #endif // CPPREFERENCE_STDVER >= 2014 diff --git a/headers/limits b/headers/limits index 9611e7fd8..ec3fecb0f 100644 --- a/headers/limits +++ b/headers/limits @@ -69,39 +69,39 @@ public: static T signaling_NaN(); static T denorm_min(); #else - static constexpr bool is_specialized; - static constexpr bool is_signed; - static constexpr bool is_integer; - static constexpr bool is_exact; - static constexpr bool has_infinity; - static constexpr bool has_quiet_NaN; - static constexpr bool has_signaling_NaN; - static constexpr float_denorm_style has_denorm; - static constexpr bool has_denorm_loss; - static constexpr float_round_style round_style; - static constexpr bool is_iec559; - static constexpr bool is_bounded; - static constexpr bool is_modulo; - static constexpr int digits; - static constexpr int digits10; - static constexpr int max_digits10; // new in C++11 - static constexpr int radix; - static constexpr int min_exponent; - static constexpr int min_exponent10; - static constexpr int max_exponent; - static constexpr int max_exponent10; - static constexpr bool traps; - static constexpr bool tinyness_before; + static constexpr bool is_specialized = false; + static constexpr bool is_signed = false; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_indeterminate; + static constexpr bool has_denorm_loss = false; + static constexpr float_round_style round_style = round_indeterminate; + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + static constexpr int digits = 0; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; // new in C++11 + static constexpr int radix = 0; + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; - static constexpr T min(); - static constexpr T lowest(); - static constexpr T max(); - static constexpr T epsilon(); - static constexpr T round_error(); - static constexpr T infinity(); - static constexpr T quiet_NaN(); - static constexpr T signaling_NaN(); - static constexpr T denorm_min(); + static constexpr T min() { return {}; } + static constexpr T lowest() { return {}; } + static constexpr T max() { return {}; } + static constexpr T epsilon() { return {}; } + static constexpr T round_error() { return {}; } + static constexpr T infinity() { return {}; } + static constexpr T quiet_NaN() { return {}; } + static constexpr T signaling_NaN() { return {}; } + static constexpr T denorm_min() { return {}; } #endif }; diff --git a/headers/list b/headers/list index 1b8806c5f..9391c3aaf 100644 --- a/headers/list +++ b/headers/list @@ -70,6 +70,7 @@ public: list(size_type count, const T& value, const Allocator& alloc = Allocator()); +#endif #if CPPREFERENCE_STDVER <2014 explicit list(size_type n); @@ -174,7 +175,10 @@ public: void push_back(T&& value); #endif -#if CPPREFERENCE_STDVER>= 2011 +#if CPPREFERENCE_STDVER >= 2017 + template + reference emplace_back(Args&& ... args); +#elif CPPREFERENCE_STDVER >= 2011 template void emplace_back(Args&& ... args); #endif @@ -186,7 +190,10 @@ public: void push_front(T&& value); #endif -#if CPPREFERENCE_STDVER>= 2011 +#if CPPREFERENCE_STDVER >= 2017 + template + reference emplace_front(Args&& ... args); +#elif CPPREFERENCE_STDVER >= 2011 template void emplace_front(Args&& ... args); #endif diff --git a/headers/locale b/headers/locale index 91757a18d..6f5ccc018 100644 --- a/headers/locale +++ b/headers/locale @@ -16,7 +16,10 @@ #ifndef CPPREFERENCE_LOCALE_H #define CPPREFERENCE_LOCALE_H +#include // for tm +#include // for ios_base #include // for std::allocator +#include namespace std { @@ -67,7 +70,7 @@ public: bool operator==(const locale& other) const; bool operator!=(const locale& other) const; - template + template bool operator()(const basic_string& s1, const basic_string& s2) const; @@ -82,12 +85,18 @@ template > class wstring_convert { public: + + using byte_string = basic_string, Byte_alloc>; + using wide_string = basic_string, Wide_alloc>; + using state_type = typename Codecvt::state_type; + using int_type = typename wide_string::traits_type::int_type; + explicit wstring_convert(Codecvt* pcvt = new Codecvt); wstring_convert(Codecvt* pcvt, state_type state); explicit wstring_convert(const byte_string& byte_err, const wide_string& wide_err = wide_string()); #if CPPREFERENCE_STDVER >= 2014 - wstring_convert(const std::wstring_convert&) = delete; + wstring_convert(const wstring_convert&) = delete; #endif ~wstring_convert(); @@ -114,11 +123,18 @@ class wbuffer_convert : public std::basic_streambuf { public: typedef typename Codecvt::state_type state_type; +#if CPPREFERENCE_STDVER >= 2011 + explicit wbuffer_convert(std::streambuf* bytebuf = nullptr, + Codecvt* pcvt = new Codecvt, + state_type state = state_type()); +#else explicit wbuffer_convert(std::streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, state_type state = state_type()); +#endif + #if CPPREFERENCE_STDVER >= 2014 - wbuffer_convert(const std::wbuffer_convert&) = delete; + wbuffer_convert(const wbuffer_convert&) = delete; #endif ~wbuffer_convert(); @@ -235,54 +251,57 @@ public: explicit codecvt(std::size_t refs = 0); - result out(StateT& state, + result out(State& state, const InternT* from, const InternT* from_end, const InternT*& from_next, ExternT* to, ExternT* to_end, ExternT*& to_next) const; - result in(stateT& state, - const externT* from, - const externT* from_end, - const externT*& from_next, - internT* to, - internT* to_end, - internT*& to_next) const; - result unshift(StateT& state, + + result in(State& state, + const ExternT* from, + const ExternT* from_end, + const ExternT*& from_next, + InternT* to, + InternT* to_end, + InternT*& to_next) const; + + result unshift(State& state, ExternT* to, ExternT* to_end, ExternT*& to_next) const; + int encoding() const; bool always_noconv() const; - int length(StateT& state, + int length(State& state, const ExternT* from, const ExternT* from_end, std::size_t max) const; int max_length() const; protected: - virtual result do_out(StateT& state, + virtual result do_out(State& state, const InternT* from, const InternT* from_end, const InternT*& from_next, ExternT* to, ExternT* to_end, ExternT*& to_next) const; - virtual result do_in(stateT& state, - const externT* from, - const externT* from_end, - const externT*& from_next, - internT* to, - internT* to_end, - internT*& to_next) const; - virtual result do_unshift(StateT& state, + virtual result do_in(State& state, + const ExternT* from, + const ExternT* from_end, + const ExternT*& from_next, + InternT* to, + InternT* to_end, + InternT*& to_next) const; + virtual result do_unshift(State& state, ExternT* to, ExternT* to_end, ExternT*& to_next) const; virtual int do_encoding() const; virtual bool do_always_noconv() const; - virtual int do_length(StateT& state, + virtual int do_length(State& state, const ExternT* from, const ExternT* from_end, std::size_t max) const; @@ -353,8 +372,8 @@ public: std::ios_base::iostate& err, std::tm* t) const; iter_type get_monthname(iter_type beg, iter_type end, std::ios_base& str, std::ios_base::iostate& err, std::tm* t) const; - iter_type do_get_year(iter_type s, iter_type end, std::ios_base& str, - std::ios_base::iostate& err, std::tm* t) const; + iter_type get_year(iter_type s, iter_type end, std::ios_base& str, + std::ios_base::iostate& err, std::tm* t) const; #if CPPREFERENCE_STDVER >= 2011 iter_type get(iter_type beg, iter_type end, std::ios_base& str, @@ -364,8 +383,8 @@ public: protected: virtual dateorder do_date_order() const; - virtual iter_type get_time(iter_type beg, iter_type end, std::ios_base& str, - std::ios_base::iostate& err, std::tm* t) const; + virtual iter_type do_get_time(iter_type beg, iter_type end, std::ios_base& str, + std::ios_base::iostate& err, std::tm* t) const; virtual iter_type do_get_date(iter_type beg, iter_type end, std::ios_base& str, std::ios_base::iostate& err, std::tm* t) const; virtual iter_type do_get_weekday(iter_type beg, iter_type end, std::ios_base& str, @@ -573,7 +592,7 @@ protected: virtual ~money_put(); }; -template +template class moneypunct : public money_base, public locale::facet { public: typedef CharT char_type; diff --git a/headers/map b/headers/map index b326f2951..7f77b82a0 100644 --- a/headers/map +++ b/headers/map @@ -20,13 +20,14 @@ #include #endif -namespace std { - #include // for size_t, ptrdiff_t #include // for std::reverse_iterator +#include // for less #include // for std::allocator #include // for std::pair +namespace std { + template < class Key, class T, @@ -38,7 +39,6 @@ public: typedef T mapped_type; typedef pair value_type; typedef Compare key_compare; - typedef Compare value_compare; typedef Allocator allocator_type; typedef size_t size_type; // actual type unspecified typedef ptrdiff_t difference_type; // actual type not specified @@ -68,8 +68,8 @@ public: class value_compare { public: typedef bool result_type; - typedef first_argument_type value_type; - typedef second_argument_type value_type; + typedef value_type first_argument_type ; + typedef value_type second_argument_type; bool operator()(const value_type& lhs, const value_type& rhs) const; protected: @@ -77,14 +77,9 @@ public: Compare comp; }; -#if CPPREFERENCE_STDVER <2014 - explicit map(const Compare& comp = Compare(), - const Allocator& alloc = Allocator()); -#else map(); explicit map(const Compare& comp, const Allocator& alloc = Allocator()); -#endif #if CPPREFERENCE_STDVER>= 2011 explicit map(const Allocator& alloc); @@ -184,6 +179,20 @@ public: template void insert(InputIt first, InputIt last); +#if CPPREFERENCE_STDVER >= 2017 + template + std::pair insert_or_assign(const Key& key, M&& obj); + + template + std::pair insert_or_assign(Key&& key, M&& obj); + + template + iterator insert_or_assign(const_iterator hint, const Key& key, M&& obj); + + template + iterator insert_or_assign(const_iterator hint, Key&& key, M&& obj); +#endif + #if CPPREFERENCE_STDVER>= 2011 template std::pair emplace(Args&& ... args); @@ -192,6 +201,20 @@ public: iterator emplace_hint(const_iterator hint, Args&& ... args); #endif +#if CPPREFERENCE_STDVER >= 2017 + template + std::pair try_emplace(const Key& key, Args&& ... args); + + template + std::pair try_emplace(Key&& key, Args&& ... args); + + template + std::pair try_emplace(const_iterator hint, const Key& key, Args&& ... args); + + template + std::pair try_emplace(const_iterator hint, Key&& key, Args&& ... args); +#endif + #if CPPREFERENCE_STDVER <2011 void erase(iterator pos); void erase(iterator first, iterator last); @@ -295,7 +318,6 @@ public: typedef T mapped_type; typedef pair value_type; typedef Compare key_compare; - typedef Compare value_compare; typedef Allocator allocator_type; typedef size_t size_type; // actual type unspecified typedef ptrdiff_t difference_type; // actual type not specified @@ -325,8 +347,8 @@ public: class value_compare { public: typedef bool result_type; - typedef first_argument_type value_type; - typedef second_argument_type value_type; + typedef value_type first_argument_type; + typedef value_type second_argument_type; bool operator()(const value_type& lhs, const value_type& rhs) const; protected: @@ -334,14 +356,9 @@ public: Compare comp; }; -#if CPPREFERENCE_STDVER <2014 - explicit multimap(const Compare& comp = Compare(), - const Allocator& alloc = Allocator()); -#else multimap(); explicit multimap(const Compare& comp, const Allocator& alloc = Allocator()); -#endif #if CPPREFERENCE_STDVER>= 2011 explicit multimap(const Allocator& alloc); diff --git a/headers/memory b/headers/memory index 9a74fa791..a578e193f 100644 --- a/headers/memory +++ b/headers/memory @@ -16,11 +16,18 @@ #ifndef CPPREFERENCE_MEMORY_H #define CPPREFERENCE_MEMORY_H +#include // for exception +#include // for basic_ostream +#include // for output_iterator_tag #include // for std::pair namespace std { +template class auto_ptr; + #if CPPREFERENCE_STDVER>= 2011 +template class weak_ptr; + template struct default_delete { constexpr default_delete() = default; @@ -42,11 +49,10 @@ template < public: // SIMPLIFIED: the array specialization is omitted -#if CPPREFERENCE_SIMPLIFY_TYPEDEFS + // SIMPLIFIED: pointer would be std::remove_reference::type::pointer if that type + // exists, but our default_delete does not have that member type typedef T* pointer; -#else - typedef typename std::remove_reference::type::pointer pointer; -#endif + typedef T element_type; typedef Deleter deleter_type; @@ -83,7 +89,7 @@ public: explicit operator bool() const; T& operator*() const; // SIMPLIFIED - pointer operator->(); + pointer operator->() const; // only in array versions T& operator[](size_t i) const; @@ -102,7 +108,6 @@ unique_ptr make_unique(Args&& ... args); #endif - template class shared_ptr { public: typedef T element_type; @@ -327,12 +332,15 @@ void swap(weak_ptr& lhs, weak_ptr& rhs); #endif // CPPREFERENCE_STDVER>= 2011 +template +class auto_ptr_ref; + template class auto_ptr { public: typedef T element_type; - explicit auto_ptr(X* p = 0); + explicit auto_ptr(T* p = 0); auto_ptr(auto_ptr& r); @@ -349,7 +357,8 @@ public: template auto_ptr& operator=(auto_ptr& r); - auto_ptr& operator=(auto_ptr_ref m); + template + auto_ptr& operator=(auto_ptr_ref m); template operator auto_ptr_ref(); @@ -408,7 +417,6 @@ public: template struct allocator { - // SIMPLIFIED: allocator specialization is not provided typedef T value_type; typedef T* pointer; typedef const T* const_pointer; @@ -434,7 +442,12 @@ struct allocator { pointer address(reference x) const; const_pointer address(const_reference x) const; - pointer allocate(size_type n, std::allocator::const_pointer hint = 0); +#if CPPREFERENCE_STDVER >= 2011 + pointer allocate(size_type n, void* hint = nullptr); +#else + pointer allocate(size_type n, void* hint = 0); +#endif + void deallocate(pointer p, size_type n); size_type max_size() const; @@ -449,6 +462,19 @@ struct allocator { void destroy(U* p); }; +template<> +struct allocator { + typedef void value_type; + typedef void* pointer; + typedef const void* const_pointer; +#if CPPREFERENCE_STDVER>= 2014 + typedef true_type propagate_on_container_move_assignment; +#endif + template struct rebind { + typedef allocator other; + }; +}; + template bool operator==(const allocator& lhs, const allocator& rhs); @@ -475,10 +501,10 @@ struct allocator_traits { // SIMPLIFIED: actually is alias template and uses Alloc::rebind template - class rebind_alloc : public Alloc {}; + class rebind_alloc : public Alloc {}; // SIMPLIFIED: actually is alias template template - class rebind_traits : public allocator_traits> {}; + class rebind_traits : public allocator_traits> {}; static pointer allocate(Alloc& a, size_type n); static pointer allocate(Alloc& a, size_type n, const_void_pointer hint); @@ -510,7 +536,7 @@ enum class pointer_safety { template struct pointer_traits { typedef Ptr pointer; - typedef void element_type; // SIMPLIFIED + typedef int element_type; // SIMPLIFIED typedef ptrdiff_t difference_type; template diff --git a/headers/mutex b/headers/mutex index 170a73b21..d38a68d44 100644 --- a/headers/mutex +++ b/headers/mutex @@ -18,6 +18,8 @@ #if CPPREFERENCE_STDVER>= 2011 +#include + namespace std { struct defer_lock_t { }; diff --git a/headers/new b/headers/new index 9fe03e9df..08970b72d 100644 --- a/headers/new +++ b/headers/new @@ -16,6 +16,8 @@ #ifndef CPPREFERENCE_NEW_H #define CPPREFERENCE_NEW_H +#include + namespace std { /* SIMPLIFIED: these are implicitly declared even if is not included. @@ -65,7 +67,7 @@ std::new_handler get_new_handler(); #endif std::new_handler set_new_handler(std::new_handler new_p); -class bad_alloc : public std::exception { +class bad_alloc : public exception { public: bad_alloc(); bad_alloc& operator=(const bad_alloc& other); diff --git a/headers/optional b/headers/optional new file mode 100644 index 000000000..2051f610d --- /dev/null +++ b/headers/optional @@ -0,0 +1,232 @@ +/* Copyright (C) 2019 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_OPTIONAL_H +#define CPPREFERENCE_OPTIONAL_H + +#if CPPREFERENCE_STDVER >= 2017 + +#include // hash +#include // in_place_t, ... +#include // decay_t +#include // exception + +namespace std { + +struct nullopt_t {}; + +inline constexpr nullopt_t nullopt; + +class bad_optional_access : public exception { +public: + ~bad_optional_access() override; + const char * what() const override; +}; + +template +class optional { +public: + using value_type = T; + + constexpr optional(); + constexpr optional(std::nullopt_t); + constexpr optional(const optional& other); + + constexpr optional(optional&& other); + + template + optional(const optional& other); + + template + optional(optional&& other); + + template + constexpr explicit optional(in_place_t, Args&&... args); + + template + constexpr explicit optional(in_place_t, + initializer_list ilist, + Args&&... args); + + template + constexpr optional(U&& value); + + ~optional(); + + optional& operator=(std::nullopt_t); + + constexpr optional& operator=(const optional& other); + + constexpr optional& operator=(optional&& other); + + template + optional& operator=(U&& value); + + template + optional& operator=(const optional& other); + + template + optional& operator=(optional&& other); + + constexpr const T* operator->() const; + + constexpr T* operator->(); + + constexpr const T& operator*() const&; + + constexpr T& operator*() &; + + constexpr const T&& operator*() const&&; + + constexpr T&& operator*() &&; + + constexpr explicit operator bool() const; + + constexpr bool has_value() const; + + constexpr T& value() &; + constexpr const T & value() const &; + + constexpr T&& value() &&; + constexpr const T&& value() const &&; + + template< class U > + constexpr T value_or(U&& default_value) const&; + + template< class U > + constexpr T value_or(U&& default_value) &&; + + void swap(optional& other); + + void reset(); + + template + T& emplace(Args&&... args); + + template + T& emplace(initializer_list ilist, Args&&... args); +}; + +template +constexpr bool operator==(const optional& lhs, const optional& rhs); + +template +constexpr bool operator!=(const optional& lhs, const optional& rhs); + +template +constexpr bool operator<(const optional& lhs, const optional& rhs); + +template +constexpr bool operator<=(const optional& lhs, const optional& rhs); + +template +constexpr bool operator>(const optional& lhs, const optional& rhs); + +template +constexpr bool operator>=(const optional& lhs, const optional& rhs); + +template +constexpr bool operator==(const optional& opt, nullopt_t); + +template +constexpr bool operator==(nullopt_t, const optional& opt); + +template +constexpr bool operator!=(const optional& opt, nullopt_t); + +template +constexpr bool operator!=(nullopt_t, const optional& opt); + +template +constexpr bool operator<(const optional& opt, nullopt_t); + +template +constexpr bool operator<(nullopt_t, const optional& opt); + +template +constexpr bool operator<=(const optional& opt, nullopt_t); + +template +constexpr bool operator<=(nullopt_t, const optional& opt); + +template +constexpr bool operator>(const optional& opt, nullopt_t); + +template +constexpr bool operator>(nullopt_t, const optional& opt); + +template +constexpr bool operator>=(const optional& opt, nullopt_t); + +template +constexpr bool operator>=(nullopt_t, const optional& opt); + + +template +constexpr bool operator==(const optional& opt, const U& value); + +template +constexpr bool operator==(const T& value, const optional& opt); + +template +constexpr bool operator!=(const optional& opt, const U& value); + +template +constexpr bool operator!=(const T& value, const optional& opt); + +template +constexpr bool operator<(const optional& opt, const U& value); + +template +constexpr bool operator<(const T& value, const optional& opt); + +template +constexpr bool operator<=(const optional& opt, const U& value); + +template +constexpr bool operator<=(const T& value, const optional& opt); + +template +constexpr bool operator>(const optional& opt, const U& value); + +template +constexpr bool operator>(const T& value, const optional& opt); + +template +constexpr bool operator>=(const optional& opt, const U& value); + +template +constexpr bool operator>=(const T& value, const optional& opt); + +template +constexpr optional> make_optional(T&& value); + +template +constexpr optional make_optional(Args&&... args); + +template +constexpr optional make_optional(initializer_list il, Args&&... args); + +template +void swap(optional& lhs, optional& rhs); + +template +struct hash> {}; + + +} // namespace std + +#endif // CPPREFERENCE_STDVER >= 2017 +#endif // CPPREFERENCE_OPTIONAL_H diff --git a/headers/ostream b/headers/ostream index 690caae7b..0e7932594 100644 --- a/headers/ostream +++ b/headers/ostream @@ -16,13 +16,22 @@ #ifndef CPPREFERENCE_OSTREAM_H #define CPPREFERENCE_OSTREAM_H +#include +#include + namespace std { template < class CharT, - class Traits = std::char_traits - > class basic_ostream : virtual public std::basic_ios { + class Traits /* = std::char_traits */ +> class basic_ostream : virtual public std::basic_ios { public: + typedef CharT char_type; + typedef Traits traits_type; + typedef typename Traits::int_type int_type; + typedef typename Traits::pos_type pos_type; + typedef typename Traits::off_type off_type; + explicit basic_ostream(std::basic_streambuf* sb); virtual ~basic_ostream(); diff --git a/headers/progress b/headers/progress deleted file mode 100644 index c0f40196a..000000000 --- a/headers/progress +++ /dev/null @@ -1,11 +0,0 @@ - -done: -algorithm -array -atomic -cassert -cfenv -ciso646 -deque -list -vector diff --git a/headers/queue b/headers/queue index 704cc7593..d24bce548 100644 --- a/headers/queue +++ b/headers/queue @@ -19,6 +19,9 @@ #if CPPREFERENCE_STDVER>= 2011 #include #endif +#include +#include +#include // less namespace std { diff --git a/headers/random b/headers/random index 97c9858b2..c2e9a50c0 100644 --- a/headers/random +++ b/headers/random @@ -18,6 +18,10 @@ #if CPPREFERENCE_STDVER >= 2011 #include +#include +#include // for numeric_limits +#include // for basic_iostream, basic_ostream +#include namespace std { @@ -54,22 +58,22 @@ public: static constexpr result_type max(); }; -template +template bool operator==(const linear_congruential_engine& lhs, const linear_congruential_engine& rhs); -template +template bool operator==(const linear_congruential_engine& lhs, const linear_congruential_engine& rhs); template + class UIntType, UIntType a, UIntType c, UIntType m> std::basic_ostream& operator<<(std::basic_ostream& ost, const linear_congruential_engine& e); template + class UIntType, UIntType a, UIntType c, UIntType m> std::basic_istream& operator>>(std::basic_istream& ist, linear_congruential_engine& e); @@ -86,24 +90,25 @@ template < > class mersenne_twister_engine { public: typedef UIntType result_type; - static constexpr size_t word_size; - static constexpr size_t state_size; - static constexpr size_t shift_size; - static constexpr size_t mask_bits; - static constexpr UIntType xor_mask; - static constexpr size_t tampering_u; - static constexpr UIntType tampering_d; - static constexpr size_t tampering_s; - static constexpr UIntType tampering_b; - static constexpr size_t tampering_t; - static constexpr UIntType tampering_c; - static constexpr size_t tampering_l; - static constexpr UIntType initialization_multiplier; + static constexpr size_t word_size = 0; + static constexpr size_t state_size = 0; + static constexpr size_t shift_size = 0; + static constexpr size_t mask_bits = 0; + static constexpr UIntType xor_mask = 0; + static constexpr size_t tampering_u = 0; + static constexpr UIntType tampering_d = 0; + static constexpr size_t tampering_s = 0; + static constexpr UIntType tampering_b = 0; + static constexpr size_t tampering_t = 0; + static constexpr UIntType tampering_c = 0; + static constexpr size_t tampering_l = 0; + static constexpr UIntType initialization_multiplier = 0; + static constexpr UIntType default_seed = 0; explicit mersenne_twister_engine(result_type value = default_seed); template - explicit mersenne_twister_engine(Sseq& s); + explicit mersenne_twister_engine(Sseq& seed); mersenne_twister_engine(const mersenne_twister_engine& other); @@ -124,7 +129,7 @@ template + UIntType c, size_t l, UIntType f> bool operator==(const mersenne_twister_engine& lhs, const mersenne_twister_engine& rhs); @@ -132,7 +137,7 @@ template + UIntType c, size_t l, UIntType f> bool operator==(const mersenne_twister_engine& lhs, const mersenne_twister_engine& rhs); @@ -142,7 +147,7 @@ template + UIntType c, size_t l, UIntType f> std::basic_ostream& operator<<(std::basic_ostream& ost, const mersenne_twister_engine& e); @@ -153,7 +158,7 @@ template + UIntType c, size_t l, UIntType f> std::basic_istream& operator>>(std::basic_istream& ist, mersenne_twister_engine& e); @@ -176,15 +181,15 @@ template < > class subtract_with_carry_engine { public: typedef UIntType result_type; - static constexpr size_t word_size; - static constexpr size_t short_lag; - static constexpr size_t long_lag; - static constexpr UIntType default_seed; + static constexpr size_t word_size = 0; + static constexpr size_t short_lag = 0; + static constexpr size_t long_lag = 0; + static constexpr UIntType default_seed = 0; explicit subtract_with_carry_engine(result_type value = default_seed); template - explicit subtract_with_carry_engine(Sseq& s); + explicit subtract_with_carry_engine(Sseq& seed); subtract_with_carry_engine(const subtract_with_carry_engine& other); @@ -201,28 +206,28 @@ public: static constexpr result_type max(); }; -template +template bool operator==(const subtract_with_carry_engine& lhs, const subtract_with_carry_engine& rhs); -template +template bool operator==(const subtract_with_carry_engine& lhs, const subtract_with_carry_engine& rhs); template + class UIntType, size_t w, size_t s, size_t r> std::basic_ostream& operator<<(std::basic_ostream& ost, const subtract_with_carry_engine& e); template + class UIntType, size_t w, size_t s, size_t r> std::basic_istream& operator>>(std::basic_istream& ist, subtract_with_carry_engine& e); typedef std::subtract_with_carry_engine ranlux24_base; -typedef std::subtract_with_carry_engine ranlex48_base; +typedef std::subtract_with_carry_engine ranlux48_base; template < class Engine, @@ -230,8 +235,8 @@ template < > class discard_block_engine { public: typedef typename Engine::result_type result_type; - static constexpr size_t block_size; - static constexpr size_t used_size; + static constexpr size_t block_size = 0; + static constexpr size_t used_size = 0; discard_block_engine(); @@ -258,22 +263,22 @@ public: static constexpr result_type max(); }; -template +template bool operator==(const discard_block_engine& lhs, const discard_block_engine& rhs); -template +template bool operator!=(const discard_block_engine& lhs, const discard_block_engine& rhs); template + class Engine, size_t p, size_t r> std::basic_ostream& operator<<(std::basic_ostream& ost, const discard_block_engine& e); template + class Engine, size_t p, size_t r> std::basic_istream& operator>>(std::basic_istream& ist, discard_block_engine& e); @@ -320,7 +325,7 @@ template < > class shuffle_order_engine { public: typedef typename Engine::result_type result_type; - static constexpr size_t table_size; + static constexpr size_t table_size = 0; shuffle_order_engine(); @@ -356,37 +361,37 @@ public: seed_seq(); seed_seq(const seed_seq&) = delete; - template + template seed_seq(InputIt begin, InputIt end); - template + template seed_seq(std::initializer_list il); - template + template void generate(RandomIt begin, RandomIt end); std::size_t size() const; - template + template void param(OutputIt dest) const; }; -template +template class uniform_int_distribution { public: typedef IntType result_type; typedef void* param_type; // TODO explicit uniform_int_distribution(IntType a = 0, - IntType b = std::numeric_limits::max()); + IntType b = numeric_limits::max()); explicit uniform_int_distribution(const param_type& params); void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type a() const; @@ -400,23 +405,23 @@ public: result_type max() const; }; -template +template bool operator==(const uniform_int_distribution& lhs, const uniform_int_distribution& rhs); -template +template bool operator!=(const uniform_int_distribution& lhs, const uniform_int_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const uniform_int_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, uniform_int_distribution& d); -template +template class uniform_real_distribution { public: typedef RealType result_type; @@ -427,10 +432,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type a() const; @@ -444,23 +449,23 @@ public: result_type max() const; }; -template +template bool operator==(const uniform_real_distribution& lhs, const uniform_real_distribution& rhs); -template +template bool operator!=(const uniform_real_distribution& lhs, const uniform_real_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const uniform_real_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, uniform_real_distribution& d); -template +template RealType generate_canonical(Generator& g); class bernoulli_distribution { @@ -473,10 +478,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); double p() const; @@ -502,7 +507,7 @@ template std::basic_istream& operator>>(std::basic_istream& ist, bernoulli_distribution& d); -template +template class binomial_distribution { public: typedef IntType result_type; @@ -513,10 +518,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); double p() const; @@ -530,23 +535,23 @@ public: }; -template +template bool operator==(const binomial_distribution& lhs, const binomial_distribution& rhs); -template +template bool operator!=(const binomial_distribution& lhs, const binomial_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const binomial_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, binomial_distribution& d); -template +template class negative_binomial_distribution { public: typedef IntType result_type; @@ -557,10 +562,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); double p() const; @@ -574,23 +579,23 @@ public: }; -template +template bool operator==(const negative_binomial_distribution& lhs, const negative_binomial_distribution& rhs); -template +template bool operator!=(const negative_binomial_distribution& lhs, const negative_binomial_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const negative_binomial_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, negative_binomial_distribution& d); -template +template class geometric_distribution { public: typedef IntType result_type; @@ -601,10 +606,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); double p() const; @@ -617,23 +622,23 @@ public: }; -template +template bool operator==(const geometric_distribution& lhs, const geometric_distribution& rhs); -template +template bool operator!=(const geometric_distribution& lhs, const geometric_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const geometric_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, geometric_distribution& d); -template +template class poisson_distribution { public: typedef IntType result_type; @@ -644,10 +649,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); double mean() const; @@ -660,23 +665,23 @@ public: }; -template +template bool operator==(const poisson_distribution& lhs, const poisson_distribution& rhs); -template +template bool operator!=(const poisson_distribution& lhs, const poisson_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const poisson_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, poisson_distribution& d); -template +template class exponential_distribution { public: typedef RealType result_type; @@ -687,10 +692,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type lambda() const; @@ -702,23 +707,23 @@ public: result_type max() const; }; -template +template bool operator==(const exponential_distribution& lhs, const exponential_distribution& rhs); -template +template bool operator!=(const exponential_distribution& lhs, const exponential_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const exponential_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, exponential_distribution& d); -template +template class gamma_distribution { public: typedef RealType result_type; @@ -729,10 +734,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type alpha() const; @@ -745,23 +750,23 @@ public: result_type max() const; }; -template +template bool operator==(const gamma_distribution& lhs, const gamma_distribution& rhs); -template +template bool operator!=(const gamma_distribution& lhs, const gamma_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const gamma_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, gamma_distribution& d); -template +template class weibull_distribution { public: typedef RealType result_type; @@ -772,10 +777,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type a() const; @@ -788,23 +793,23 @@ public: result_type max() const; }; -template +template bool operator==(const weibull_distribution& lhs, const weibull_distribution& rhs); -template +template bool operator!=(const weibull_distribution& lhs, const weibull_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const weibull_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, weibull_distribution& d); -template +template class extreme_value_distribution { public: typedef RealType result_type; @@ -815,10 +820,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type a() const; @@ -831,23 +836,23 @@ public: result_type max() const; }; -template +template bool operator==(const extreme_value_distribution& lhs, const extreme_value_distribution& rhs); -template +template bool operator!=(const extreme_value_distribution& lhs, const extreme_value_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const extreme_value_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, extreme_value_distribution& d); -template +template class normal_distribution { public: typedef RealType result_type; @@ -858,10 +863,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type mean() const; @@ -874,23 +879,23 @@ public: result_type max() const; }; -template +template bool operator==(const normal_distribution& lhs, const normal_distribution& rhs); -template +template bool operator!=(const normal_distribution& lhs, const normal_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const normal_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, normal_distribution& d); -template +template class lognormal_distribution { public: typedef RealType result_type; @@ -901,10 +906,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type m() const; @@ -917,23 +922,23 @@ public: result_type max() const; }; -template +template bool operator==(const lognormal_distribution& lhs, const lognormal_distribution& rhs); -template +template bool operator!=(const lognormal_distribution& lhs, const lognormal_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const lognormal_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, lognormal_distribution& d); -template +template class chi_squared_distribution { public: typedef RealType result_type; @@ -944,10 +949,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type n() const; @@ -959,23 +964,23 @@ public: result_type max() const; }; -template +template bool operator==(const chi_squared_distribution& lhs, const chi_squared_distribution& rhs); -template +template bool operator!=(const chi_squared_distribution& lhs, const chi_squared_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const chi_squared_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, chi_squared_distribution& d); -template +template class cauchy_distribution { public: typedef RealType result_type; @@ -986,10 +991,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type a() const; @@ -1002,23 +1007,23 @@ public: result_type max() const; }; -template +template bool operator==(const cauchy_distribution& lhs, const cauchy_distribution& rhs); -template +template bool operator!=(const cauchy_distribution& lhs, const cauchy_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const cauchy_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, cauchy_distribution& d); -template +template class fisher_f_distribution { public: typedef RealType result_type; @@ -1029,10 +1034,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type m() const; @@ -1045,23 +1050,23 @@ public: result_type max() const; }; -template +template bool operator==(const fisher_f_distribution& lhs, const fisher_f_distribution& rhs); -template +template bool operator!=(const fisher_f_distribution& lhs, const fisher_f_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const fisher_f_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, fisher_f_distribution& d); -template +template class student_t_distribution { public: typedef RealType result_type; @@ -1072,10 +1077,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); result_type n() const; @@ -1087,23 +1092,23 @@ public: result_type max() const; }; -template +template bool operator==(const student_t_distribution& lhs, const student_t_distribution& rhs); -template +template bool operator!=(const student_t_distribution& lhs, const student_t_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const student_t_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, student_t_distribution& d); -template +template class discrete_distribution { public: typedef IntType result_type; @@ -1111,12 +1116,12 @@ public: discrete_distribution(); - template + template discrete_distribution(InputIt first, InputIt last); discrete_distribution(std::initializer_list weights); - template + template discrete_distribution(std::size_t count, double xmin, double xmax, UnaryOperation unary_op); @@ -1124,10 +1129,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); std::vector probabilities() const; @@ -1140,23 +1145,23 @@ public: }; -template +template bool operator==(const discrete_distribution& lhs, const discrete_distribution& rhs); -template +template bool operator!=(const discrete_distribution& lhs, const discrete_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const discrete_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, discrete_distribution& d); -template +template class piecewise_constant_distribution { public: typedef RealType result_type; @@ -1164,15 +1169,15 @@ public: piecewise_constant_distribution(); - template + template piecewise_constant_distribution(InputIt1 first_i, InputIt1 last_i, InputIt2 first_w); - template + template piecewise_constant_distribution(std::initializer_list bl, UnaryOperation fw); - template + template piecewise_constant_distribution(std::size_t nw, RealType xmin, RealType xmax, UnaryOperation fw); @@ -1181,10 +1186,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); std::vector intervals() const; @@ -1197,23 +1202,23 @@ public: result_type max() const; }; -template +template bool operator==(const piecewise_constant_distribution& lhs, const piecewise_constant_distribution& rhs); -template +template bool operator!=(const piecewise_constant_distribution& lhs, const piecewise_constant_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const piecewise_constant_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, piecewise_constant_distribution& d); -template +template class piecewise_linear_distribution { public: typedef RealType result_type; @@ -1221,15 +1226,15 @@ public: piecewise_linear_distribution(); - template + template piecewise_linear_distribution(InputIt1 first_i, InputIt1 last_i, InputIt2 first_w); - template + template piecewise_linear_distribution(std::initializer_list ilist, UnaryOperation fw); - template + template piecewise_linear_distribution(std::size_t nw, RealType xmin, RealType xmax, UnaryOperation fw); @@ -1238,10 +1243,10 @@ public: void reset(); - template + template result_type operator()(Generator& g); - template + template result_type operator()(Generator& g, const param_type& params); std::vector intervals() const; @@ -1254,19 +1259,19 @@ public: result_type max() const; }; -template +template bool operator==(const piecewise_linear_distribution& lhs, const piecewise_linear_distribution& rhs); -template +template bool operator!=(const piecewise_linear_distribution& lhs, const piecewise_linear_distribution& rhs); -template +template std::basic_ostream& operator<<(std::basic_ostream& ost, const piecewise_linear_distribution& d); -template +template std::basic_istream& operator>>(std::basic_istream& ist, piecewise_linear_distribution& d); diff --git a/headers/ratio b/headers/ratio index 4f754d480..a73671712 100644 --- a/headers/ratio +++ b/headers/ratio @@ -27,12 +27,13 @@ template type; - static constexpr intmax_t num; - static constexpr intmax_t den; + static constexpr intmax_t num = Num; + static constexpr intmax_t den = Denom; }; -typedef ratio<1, 1000000000000000000000000> yocto; -typedef ratio<1, 1000000000000000000000> zepto; +// only defined if intmax_t can represent the denominator +// typedef ratio<1, 1000000000000000000000000> yocto; +// typedef ratio<1, 1000000000000000000000> zepto; typedef ratio<1, 1000000000000000000> atto; typedef ratio<1, 1000000000000000> femto; typedef ratio<1, 1000000000000> pico; @@ -49,8 +50,9 @@ typedef ratio< 1000000000, 1> giga; typedef ratio< 1000000000000, 1> tera; typedef ratio< 1000000000000000, 1> peta; typedef ratio< 1000000000000000000, 1> exa; -typedef ratio< 1000000000000000000000, 1> zetta; -typedef ratio<1000000000000000000000000, 1> yotta; +// only defined if intmax_t can represent the nominator +// typedef ratio< 1000000000000000000000, 1> zetta; +// typedef ratio<1000000000000000000000000, 1> yotta; // SIMPLIFIED: the following are alias templates template diff --git a/headers/regex b/headers/regex index 1d1922d7e..6d48a417e 100644 --- a/headers/regex +++ b/headers/regex @@ -20,53 +20,57 @@ #include // for std::initializer_list #include // for std::allocator +#include +#include +#include +#include namespace std { namespace regex_constants { -typedef int syntax_option_type; // actually unspecified -constexpr syntax_option_type icase; -constexpr syntax_option_type nosubs; -constexpr syntax_option_type optimize; -constexpr syntax_option_type collate; -constexpr syntax_option_type ECMAScript; -constexpr syntax_option_type basic; -constexpr syntax_option_type extended; -constexpr syntax_option_type awk; -constexpr syntax_option_type grep; -constexpr syntax_option_type egrep; +typedef CPPREFERENCE_UNSPECIFIED_TYPE syntax_option_type; +constexpr syntax_option_type icase = 0; +constexpr syntax_option_type nosubs = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type optimize = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type collate = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type ECMAScript = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type basic = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type extended = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type awk = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type grep = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr syntax_option_type egrep = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; -typedef int match_flag_type; // actually unspecified +typedef CPPREFERENCE_UNSPECIFIED_TYPE match_flag_type; constexpr match_flag_type match_default = 0; -constexpr match_flag_type match_not_bol; -constexpr match_flag_type match_not_eol; -constexpr match_flag_type match_not_bow; -constexpr match_flag_type match_not_eow; -constexpr match_flag_type match_any; -constexpr match_flag_type match_not_null; -constexpr match_flag_type match_continuous; -constexpr match_flag_type match_prev_avail; +constexpr match_flag_type match_not_bol = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type match_not_eol = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type match_not_bow = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type match_not_eow = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type match_any = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type match_not_null = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type match_continuous = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type match_prev_avail = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; constexpr match_flag_type format_default = 0; -constexpr match_flag_type format_sed; -constexpr match_flag_type format_no_copy; -constexpr match_flag_type format_first_only; - -typedef int error_type; // actually unspecified - -constexpr error_type error_collate; -constexpr error_type error_ctype; -constexpr error_type error_escape; -constexpr error_type error_backref; -constexpr error_type error_brack; -constexpr error_type error_paren; -constexpr error_type error_brace; -constexpr error_type error_badbrace; -constexpr error_type error_range; -constexpr error_type error_space; -constexpr error_type error_badrepeat; -constexpr error_type error_complexity; -constexpr error_type error_stack; +constexpr match_flag_type format_sed = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type format_no_copy = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr match_flag_type format_first_only = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; + +typedef CPPREFERENCE_UNSPECIFIED_TYPE error_type; + +constexpr error_type error_collate = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_ctype = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_escape = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_backref = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_brack = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_paren = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_brace = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_badbrace = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_range = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_space = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_badrepeat = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_complexity = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; +constexpr error_type error_stack = CPPREFERENCE_UNSPECIFIED_TYPE_VALUE; } // namespace regex_constants @@ -154,7 +158,7 @@ public: basic_regex& assign(basic_regex&& that); basic_regex& assign(const CharT* s, flag_type f = std::regex_constants::ECMAScript); - basic_regex& assign(const charT* ptr, size_t count, + basic_regex& assign(const CharT* ptr, size_t count, flag_type f = std::regex_constants::ECMAScript); template @@ -188,6 +192,8 @@ public: typedef typename std::iterator_traits::value_type value_type; typedef typename std::iterator_traits::difference_type difference_type; #endif + using string_type = std::basic_string; + bool matched; constexpr sub_match(); @@ -217,7 +223,7 @@ template < class Alloc = std::allocator> > class match_results { public: - typedef Allocator allocator_type; + typedef Alloc allocator_type; typedef sub_match value_type; typedef value_type& reference; typedef const value_type& const_reference; @@ -228,7 +234,7 @@ public: typedef typename std::iterator_traits::value_type char_type; typedef std::basic_string string_type; - explicit match_results(const Allocator& a = Allocator()); + explicit match_results(const Alloc& a = Alloc()); match_results(const match_results& rhs); match_results(match_results&& rhs); ~match_results(); @@ -259,16 +265,16 @@ public: const_iterator cend() const; template - OutputIter format(OutputIt out, - const char_type* fmt_first, const char_type* fmt_last, - std::regex_constants::match_flag_type flags = - std::regex_constants::format_default) const; + OutputIt format(OutputIt out, + const char_type* fmt_first, const char_type* fmt_last, + std::regex_constants::match_flag_type flags = + std::regex_constants::format_default) const; template - OutputIter format(OutputIt out, - const basic_string& fmt, - std::regex_constants::match_flag_type flags = - std::regex_constants::format_default) const; + OutputIt format(OutputIt out, + const basic_string& fmt, + std::regex_constants::match_flag_type flags = + std::regex_constants::format_default) const; template std::basic_string @@ -306,7 +312,7 @@ template < class Traits = std::regex_traits > class regex_iterator { public: - typedef match_result value_type; + typedef match_results value_type; typedef ptrdiff_t difference_type; typedef const value_type* pointer; typedef const value_type& reference; @@ -358,26 +364,26 @@ public: typedef basic_regex regex_type; regex_token_iterator(); - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, const regex_type& re, int submatch = 0, std::regex_constants::match_flag_type m = std::regex_constants::match_default); - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, const regex_type& re, const std::vector& submatches, std::regex_constants::match_flag_type m = std::regex_constants::match_default); - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, const regex_type& re, std::initializer_list submatches, std::regex_constants::match_flag_type m = std::regex_constants::match_default); template - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, const regex_type& re, const int (&submatches)[N], std::regex_constants::match_flag_type m = @@ -386,26 +392,26 @@ public: regex_token_iterator(const regex_token_iterator& other); #if CPPREFERENCE_STDVER>= 2014 - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, regex_type&& re, int submatch = 0, std::regex_constants::match_flag_type m = std::regex_constants::match_default) = delete; - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, regex_type&& re, const std::vector& submatches, std::regex_constants::match_flag_type m = std::regex_constants::match_default) = delete; - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, regex_type&& re, std::initializer_list submatches, std::regex_constants::match_flag_type m = std::regex_constants::match_default) = delete; template - regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + regex_token_iterator(BidirIt a, BidirIt b, regex_type&& re, const int (&submatches)[N], std::regex_constants::match_flag_type m = @@ -420,8 +426,8 @@ public: const value_type& operator*() const; const value_type* operator->() const; - regex_iterator& operator++(); - regex_iterator operator++(int); + regex_token_iterator& operator++(); + regex_token_iterator operator++(int); }; typedef regex_token_iterator cregex_token_iterator; @@ -483,7 +489,7 @@ bool regex_search(BidirIt first, BidirIt last, template bool regex_search(const CharT* str, - std::match_results& m, + std::match_results& m, const std::basic_regex& e, std::regex_constants::match_flag_type flags = std::regex_constants::match_default); diff --git a/headers/scoped_allocator b/headers/scoped_allocator index cc9081517..ec7ec81bc 100644 --- a/headers/scoped_allocator +++ b/headers/scoped_allocator @@ -18,6 +18,7 @@ #if CPPREFERENCE_STDVER>= 2011 +#include // for allocator_traits #include // for std::pair #include // for std::true_type @@ -62,17 +63,17 @@ public: scoped_allocator_adaptor(); - template + template scoped_allocator_adaptor(OuterA2&& outerAlloc, const InnerAllocs& ... innerAllocs); scoped_allocator_adaptor(const scoped_allocator_adaptor& other); scoped_allocator_adaptor(scoped_allocator_adaptor&& other); - template + template scoped_allocator_adaptor(const scoped_allocator_adaptor& other); - template + template scoped_allocator_adaptor(scoped_allocator_adaptor&& other); ~scoped_allocator_adaptor(); diff --git a/headers/set b/headers/set index 777ed8547..f36671354 100644 --- a/headers/set +++ b/headers/set @@ -21,6 +21,7 @@ #endif #include // for size_t, ptrdiff_t +#include // for less #include // for std::reverse_iterator #include // for std::allocator #include // for std::pair @@ -56,22 +57,16 @@ public: typedef typename std::allocator_traits::pointer pointer; typedef typename std::allocator_traits::const_pointer const_pointer; #endif - typedef T* iterator; // actual type is unspecified - typedef const T* const_iterator; // actual type is unspecified + typedef Key* iterator; // actual type is unspecified + typedef const Key* const_iterator; // actual type is unspecified typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; // constructor - -#if CPPREFERENCE_STDVER <2014 - explicit set(const Compare& comp = Compare(), - const Allocator& alloc = Allocator()); -#else set(); explicit set(const Compare& comp, const Allocator& alloc = Allocator()); -#endif #if CPPREFERENCE_STDVER>= 2011 explicit set(const Allocator& alloc); @@ -175,8 +170,10 @@ public: // lookup size_type count(const Key& key) const; +#if CPPREFERENCE_STDVER >= 2014 template size_type count(const K& x) const; +#endif iterator find(const Key& key); const_iterator find(const Key& key) const; @@ -281,22 +278,16 @@ public: typedef typename std::allocator_traits::pointer pointer; typedef typename std::allocator_traits::const_pointer const_pointer; #endif - typedef T* iterator; // actual type is unspecified - typedef const T* const_iterator; // actual type is unspecified + typedef Key* iterator; // actual type is unspecified + typedef const Key* const_iterator; // actual type is unspecified typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; // constructor - -#if CPPREFERENCE_STDVER <2014 - explicit multiset(const Compare& comp = Compare(), - const Allocator& alloc = Allocator()); -#else multiset(); explicit multiset(const Compare& comp, const Allocator& alloc = Allocator()); -#endif #if CPPREFERENCE_STDVER>= 2011 explicit multiset(const Allocator& alloc); @@ -400,8 +391,10 @@ public: // lookup size_type count(const Key& key) const; +#if CPPREFERENCE_STDVER >= 2014 template size_type count(const K& x) const; +#endif iterator find(const Key& key); const_iterator find(const Key& key) const; diff --git a/headers/shared_mutex b/headers/shared_mutex index dccf75392..23a837e2b 100644 --- a/headers/shared_mutex +++ b/headers/shared_mutex @@ -18,6 +18,9 @@ #if CPPREFERENCE_STDVER>= 2014 +#include +#include // try_to_lock_t and friends + namespace std { #if CPPREFERENCE_STDVER>= 2017 diff --git a/headers/span b/headers/span new file mode 100644 index 000000000..b83fe891a --- /dev/null +++ b/headers/span @@ -0,0 +1,120 @@ +/* Copyright (C) 2023 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_SPAN_H +#define CPPREFERENCE_SPAN_H + +#if CPPREFERENCE_STDVER >= 2020 + +#include +#include +#include + +namespace std { + +inline constexpr size_t dynamic_extent = numeric_limits::max(); + +template +class span { + using element_type = T; + using value_type = remove_cv_t; + using size_type = size_t; + using difference_type = ptrdiff_t; + using pointer = element_type*; + using const_pointer = const element_type*; + using reference = element_type&; + using const_reference = const element_type&; + using iterator = T*; // actual type is unspecified + using const_iterator = const T*; // actual type is const_iterator; + using reverse_iterator = T*; // actual type is reverse_iterator; + using const_reverse_iterator = const T*; // actual type is const_iterator; + static constexpr size_type extent = Extent; + + // constructor + constexpr span() noexcept; + + template + constexpr explicit(extent != dynamic_extent) span(It first, size_type count); + + template + constexpr explicit(extent != dynamic_extent) span(It first, End last); + + template + constexpr span(type_identity_t (&arr)[N]) noexcept; + + template + constexpr span(array& arr) noexcept; + + template + constexpr span(const array& arr) noexcept; + + template + constexpr explicit(extent != dynamic_extent) span(R&& r); + + constexpr span(const span& other) noexcept = default; + + template + constexpr explicit span(const span& s) noexcept; + + ~span() noexcept = default; + + constexpr span& operator=(const span& other) noexcept = default; + + // subviews + template + constexpr span first() const; + + template + constexpr span last() const; + + template + constexpr span subspan() const; + + constexpr span first(size_type count) const; + constexpr span last(size_type count) const; + constexpr span subspan(size_type offset, + size_type count = dynamic_extent) const; + // observers + constexpr size_type size() const noexcept; + constexpr size_type size_bytes() const noexcept; + [[nodiscard]] constexpr bool empty() const noexcept; + + // element access + constexpr reference operator[](size_type idx) const; + constexpr reference front() const; + constexpr reference back() const; + constexpr pointer data() const noexcept; + + // iterator support + constexpr iterator begin() const noexcept; + constexpr iterator end() const noexcept; + constexpr const_iterator cbegin() const noexcept; + constexpr const_iterator cend() const noexcept; + constexpr reverse_iterator rbegin() const noexcept; + constexpr reverse_iterator rend() const noexcept; + constexpr const_reverse_iterator crbegin() const noexcept; + constexpr const_reverse_iterator crend() const noexcept; +}; + +template +span as_bytes(span s) noexcept; + +template +span as_writable_bytes(span s) noexcept + +} // namespace std +#endif + +#endif // CPPREFERENCE_OSTREAM_H diff --git a/headers/sstream b/headers/sstream index 756498c8c..edce346e5 100644 --- a/headers/sstream +++ b/headers/sstream @@ -16,6 +16,7 @@ #ifndef CPPREFERENCE_SSTREAM_H #define CPPREFERENCE_SSTREAM_H +#include // for default template arguments #include // for streams #include // for std::allocator @@ -23,10 +24,15 @@ namespace std { template < class CharT, - class Traits = std::char_traits, - class Allocator = std::allocator + class Traits /* = std::char_traits */, + class Allocator /*= std::allocator */ > class basic_stringbuf : public std::basic_streambuf { public: + typedef CharT char_type; + typedef Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; #if CPPREFERENCE_STDVER>= 2011 typedef Allocator allocator_type; @@ -35,15 +41,15 @@ public: explicit basic_stringbuf(std::ios_base::openmode which = std::ios_base::in | std::ios_base::out); - explicit basic_stringbuf(const std::basic_string& new_str, + explicit basic_stringbuf(const std::basic_string& new_str, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out); #if CPPREFERENCE_STDVER>= 2011 basic_stringbuf(const basic_stringbuf& rhs) = delete; basic_stringbuf(basic_stringbuf&& rhs); - std::basic_stringbuf& operator=(std::basic_stringbuf&& rhs); - std::basic_stringbuf& operator=(const std::basic_stringbuf& rhs) = delete; - void swap(std::basic_stringbuf& rhs); + basic_stringbuf& operator=(basic_stringbuf&& rhs); + basic_stringbuf& operator=(const basic_stringbuf& rhs) = delete; + void swap(basic_stringbuf& rhs); #endif virtual ~basic_stringbuf(); @@ -53,8 +59,8 @@ public: protected: virtual int_type underflow(); - virtual int_type pbackfail(int_type c = Traits_type::eof()); - virtual int_type overflow(int_type c = Traits_type::eof()); + virtual int_type pbackfail(int_type c = traits_type::eof()); + virtual int_type overflow(int_type c = traits_type::eof()); virtual basic_streambuf* setbuf(char_type* s, streamsize n); virtual pos_type seekoff(off_type off, ios_base::seekdir dir, ios_base::openmode which = ios_base::in | ios_base::out); @@ -64,8 +70,8 @@ protected: #if CPPREFERENCE_STDVER>= 2011 template -void swap(std::basic_stringbuf& lhs, - std::basic_stringbuf& rhs); +void swap(basic_stringbuf& lhs, + basic_stringbuf& rhs); #endif typedef basic_stringbuf stringbuf; @@ -73,9 +79,9 @@ typedef basic_stringbuf wstringbuf; template < class CharT, - class Traits = std::char_traits, - class Allocator = std::allocator - > class basic_stringstream : public std::basic_iostream { + class Traits /* = std::char_traits */, + class Allocator /*= std::allocator */ +> class basic_stringstream : public std::basic_iostream { public: #if CPPREFERENCE_STDVER>= 2011 @@ -91,7 +97,7 @@ public: void swap(basic_stringstream& other); #endif - std::basic_stringbuf* rdbuf() const; + basic_stringbuf* rdbuf() const; std::basic_string str() const; void str(const std::basic_string& new_str); @@ -108,9 +114,9 @@ typedef basic_stringstream wstringstream; template < class CharT, - class Traits = std::char_traits, - class Allocator = std::allocator - > class basic_istringstream : public std::basic_ostream { + class Traits /* = std::char_traits */, + class Allocator /* = std::allocator */ +> class basic_istringstream : public std::basic_ostream { public: #if CPPREFERENCE_STDVER>= 2011 @@ -126,7 +132,7 @@ public: void swap(basic_istringstream& other); #endif - std::basic_stringbuf* rdbuf() const; + basic_stringbuf* rdbuf() const; std::basic_string str() const; void str(const std::basic_string& new_str); @@ -143,9 +149,9 @@ void swap(std::basic_istringstream& lhs, template < class CharT, - class Traits = std::char_traits, - class Allocator = std::allocator - > class basic_ostringstream : public std::basic_ostream { + class Traits /* = std::char_traits */, + class Allocator /* = std::allocator */ +> class basic_ostringstream : public std::basic_ostream { public: #if CPPREFERENCE_STDVER>= 2011 @@ -161,7 +167,7 @@ public: void swap(basic_ostringstream& other); #endif - std::basic_stringbuf* rdbuf() const; + basic_stringbuf* rdbuf() const; std::basic_string str() const; void str(const std::basic_string& new_str); diff --git a/headers/stack b/headers/stack index 75aeac408..a8c8d3577 100644 --- a/headers/stack +++ b/headers/stack @@ -20,6 +20,8 @@ #include #endif +#include + namespace std { template < diff --git a/headers/stdexcept b/headers/stdexcept index 5c3a330b1..c313b3e5a 100644 --- a/headers/stdexcept +++ b/headers/stdexcept @@ -17,6 +17,7 @@ #define CPPREFERENCE_STDEXCEPT_H #include +#include namespace std { diff --git a/headers/streambuf b/headers/streambuf index 04dc92df2..d765b508c 100644 --- a/headers/streambuf +++ b/headers/streambuf @@ -16,9 +16,11 @@ #ifndef CPPREFERENCE_STREAMBUF_H #define CPPREFERENCE_STREAMBUF_H +#include // for locale + namespace std { -template> +template*/ > class basic_streambuf { public: typedef CharT char_type; diff --git a/headers/string b/headers/string index 9d91810c5..a3c9c082b 100644 --- a/headers/string +++ b/headers/string @@ -21,11 +21,42 @@ #endif #include // for size_t, ptrdiff_t +#include // for mbstate_t +#include #include // for std::reverse_iterator #include // for std::allocator +#include +#include namespace std { +template +class char_traits { +public: + typedef CharT char_type; + typedef int int_type; // impl-defined integer type + typedef streamoff off_type; // actually impl-defined + typedef streampos pos_type; // actually impl-defined + typedef mbstate_t state_type; // actually impl-defined + + static void assign(char_type& r, const char_type& a); + static char_type* assign(char_type* p, size_t count, char_type a); + static bool eq(char_type a, char_type b); + static bool lt(char_type a, char_type b); + static char_type* move(char_type* desc, const char_type* src, size_t count); + static char_type* copy(char_type* desc, const char_type* src, size_t count); + + static int compare(const char_type* s1, const char_type* s2, size_t count); + static size_t length(const char_type* s); + static const char_type* find(const char_type* p, size_t count, const char_type& ch); + + static char_type to_char_type(int_type c); + static int_type to_int_type(char_type c); + static bool eq_int_type(int_type c1, int_type c2); + static int_type eof(); + static int_type not_eof(int_type c); +}; + template class fpos { public: @@ -58,37 +89,10 @@ typedef fpos::state_type> u16streampos; typedef fpos::state_type> u32streampos; #endif -template -class char_traits { -public: - typedef CharT char_type; - typedef int int_type; // impl-defined integer type - typedef streamoff off_type; // actually impl-defined - typedef streampos pos_type; // actually impl-defined - typedef mbstate_t state_type; // actually impl-defined - - static void assign(char_type& r, const char_type& a); - static char_type* assign(char_type* p, size_t count, char_type a); - static bool eq(char_type a, char_type b); - static bool lt(char_type a, char_type b); - static char_type* move(char_type* desc, const char_type* src, size_t count); - static char_type* copy(char_type* desc, const char_type* src, size_t count); - - static int compare(const char_type* s1, const char_type* s2, size_t count); - static size_t length(const char_type* s); - static const char_type* find(const char_type* p, size_t count, const char_type& ch); - - static char_type to_char_type(int_type c); - static int_type to_int_type(char_type c); - static bool eq_int_type(int_type c1, int_type c2); - static int_type eof(); - static int_type not_eof(int_type c); -}; - template < class CharT, - class Traits = std::char_traits, - class Allocator = std::allocator + class Traits /* = std::char_traits */, + class Allocator /* = std::allocator */ > class basic_string { public: typedef Traits traits_type; @@ -139,7 +143,7 @@ public: basic_string(const basic_string& other, size_type pos, - size_type count = std::basic_string::npos, + size_type count = npos, const Allocator& alloc = Allocator()); basic_string(const CharT* s, @@ -162,6 +166,11 @@ public: basic_string(std::initializer_list init, const Allocator& alloc = Allocator()); #endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + basic_string(basic_string_view sv, const Allocator& alloc = Allocator()); +#endif ~basic_string(); @@ -172,6 +181,11 @@ public: basic_string& operator=(basic_string&& other); basic_string& operator=(initializer_list ilist); #endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + basic_string& operator=(basic_string_view sv); +#endif basic_string& assign(size_type count, const CharT& ch); basic_string& assign(const basic_string& str); @@ -185,6 +199,12 @@ public: size_type count = npos); #endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + basic_string& assign(basic_string_view sv); +#endif + basic_string& assign(const CharT* s, size_type count); @@ -198,6 +218,13 @@ public: basic_string& assign(std::initializer_list ilist); #endif +#if CPPREFERENCE_STDVER >= 2017 + template + basic_string& assign(const T& t); + template + basic_string& assign(const T& t, size_type pos, size_type count = npos); +#endif + allocator_type get_allocator() const; // element access @@ -205,6 +232,9 @@ public: const_reference at(size_type n) const; reference operator[](size_type n); const_reference operator[](size_type n) const; +#if CPPREFERENCE_STDVER >= 2017 + operator basic_string_view() const noexcept; +#endif #if CPPREFERENCE_STDVER>= 2011 CharT& front(); @@ -212,7 +242,12 @@ public: CharT& back(); const CharT& back() const; #endif + const CharT* data() const; +#if CPPREFERENCE_STDVER >= 2017 + CharT* data(); +#endif + const CharT* c_str() const; // iterators @@ -260,6 +295,12 @@ public: size_type index_str, size_type count = npos); #endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + basic_string& insert(size_type index, basic_string_view sv); +#endif + #if CPPREFERENCE_STDVER <2011 iterator insert(iterator pos, CharT ch); void insert(iterator pos, size_type count, CharT ch); @@ -273,6 +314,15 @@ public: iterator insert(const_iterator pos, std::initializer_list ilist); #endif +#if CPPREFERENCE_STDVER >= 2017 + template + basic_string& insert(size_type pos, const T& t); + + template + basic_string& insert(size_type index, const T& t, + size_type index_str, size_type count = npos); +#endif + basic_string& erase(size_type index = 0, size_type count = npos); #if CPPREFERENCE_STDVER <2011 iterator erase(iterator pos); @@ -296,14 +346,19 @@ public: basic_string& append(size_type count, CharT ch); basic_string& append(const basic_string& str); -#if CPPREFERENCE_STDVER <2014 +#if CPPREFERENCE_STDVER >= 2014 basic_string& append(const basic_string& str, size_type pos, - size_type count); + size_type count = npos); #else basic_string& append(const basic_string& str, size_type pos, - size_type count = npos); + size_type count); +#endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + basic_string& append(basic_string_view sv); #endif basic_string& append(const CharT* s, size_type count); @@ -315,12 +370,25 @@ public: basic_string& append(std::initializer_list ilist); #endif +#if CPPREFERENCE_STDVER > 2017 + template + basic_string& append(const T& t); + + template + basic_string& append(const T& t, size_type pos, size_type count = npos); +#endif + basic_string& operator+=(const basic_string& str); basic_string& operator+=(CharT ch); basic_string& operator+=(const CharT* s); #if CPPREFERENCE_STDVER> 2011 basic_string& operator+=(std::initializer_list ilist); #endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + basic_string& operator+=(basic_string_view sv); +#endif int compare(const basic_string& str) const; int compare(size_type pos1, size_type count1, @@ -328,7 +396,6 @@ public: #if CPPREFERENCE_STDVER <2014 int compare(size_type pos1, size_type count1, - const basic_string& str, size_type pos2, size_type count2) const; #else @@ -336,12 +403,43 @@ public: const basic_string& str, size_type pos2, size_type count2 = npos) const; #endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + int compare(basic_string_view sv) const noexcept; + int compare(size_type pos1, size_type count1, + basic_string_view sv) const; +#endif + int compare(const CharT* s) const; int compare(size_type pos1, size_type count1, const CharT* s) const; int compare(size_type pos1, size_type count1, const CharT* s, size_type count2) const; +#if CPPREFERENCE_STDVER >= 2017 + template + int compare(const T& t) const; + + template + int compare(size_type pos1, size_type count1, const T& t) const; + + template + int compare(size_type pos1, size_type count1, + const T& t, + size_type pos2, size_type count2 = npos) const; +#endif + +#if CPPREFERENCE_STDVER >= 2020 + bool starts_with(basic_string_view sv) const noexcept; + bool starts_with(CharT c) const noexcept; + bool starts_with(const CharT* s) const; + + bool ends_with(basic_string_view sv) const noexcept; + bool ends_with(CharT c) const noexcept; + bool ends_with(const CharT* s) const; +#endif + basic_string& replace(size_type pos, size_type count, const basic_string& str); basic_string& replace(const_iterator first, const_iterator last, @@ -359,6 +457,15 @@ public: size_type pos2, size_type count2 = npos); #endif +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + basic_string& replace(size_type pos, size_type count, + basic_string_view sv); + basic_string& replace(const_iterator first, const_iterator last, + basic_string_view sv); +#endif + template basic_string& replace(const_iterator first, const_iterator last, InputIt first2, InputIt last2); @@ -384,6 +491,19 @@ public: basic_string& replace(const_iterator first, const_iterator last, std::initializer_list ilist); +#if CPPREFERENCE_STDVER >= 2017 + template + basic_string& replace(size_type pos,size_type count, const T& t); + + template + basic_string& replace(const_iterator first, const_iterator last, + const T& t); + + template + basic_string& replace(size_type pos, size_type count, const T& t, + size_type pos2, size_type count2 = npos); +#endif + basic_string substr(size_type pos = 0, size_type count = npos) const; @@ -395,31 +515,71 @@ public: // search size_type find(const basic_string& str, size_type pos = 0) const; + +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + size_type find(basic_string_view sv, + size_type pos = 0); +#endif + size_type find(const CharT* s, size_type pos, size_type count) const; size_type find(const CharT* s, size_type pos = 0) const; size_type find(CharT ch, size_type pos = 0) const; size_type rfind(const basic_string& str, size_type pos = npos) const; + +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + size_type rfind(basic_string_view sv, + size_type pos = npos); +#endif + size_type rfind(const CharT* s, size_type pos, size_type count) const; size_type rfind(const CharT* s, size_type pos = npos) const; size_type rfind(CharT ch, size_type pos = npos) const; size_type find_first_of(const basic_string& str, size_type pos = 0) const; +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + size_type find_first_of(basic_string_view sv, + size_type pos = 0); +#endif size_type find_first_of(const CharT* s, size_type pos, size_type count) const; size_type find_first_of(const CharT* s, size_type pos = 0) const; size_type find_first_of(CharT ch, size_type pos = 0) const; size_type find_first_not_of(const basic_string& str, size_type pos = 0) const; +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + size_type find_first_not_of(basic_string_view sv, + size_type pos = 0); +#endif size_type find_first_not_of(const CharT* s, size_type pos, size_type count) const; size_type find_first_not_of(const CharT* s, size_type pos = 0) const; size_type find_first_not_of(CharT ch, size_type pos = 0) const; size_type find_last_of(const basic_string& str, size_type pos = npos) const; +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + size_type find_last_of(basic_string_view sv, + size_type pos = npos); +#endif size_type find_last_of(const CharT* s, size_type pos, size_type count) const; size_type find_last_of(const CharT* s, size_type pos = npos) const; size_type find_last_of(CharT ch, size_type pos = npos) const; size_type find_last_not_of(const basic_string& str, size_type pos = npos) const; +#if CPPREFERENCE_STDVER >= 2017 + // SIMPLIFIED: the C++20 standard specifies a template that only accepts types convertible + // to string_view, but not to const Char* + size_type find_last_not_of(basic_string_view sv, + size_type pos = npos); +#endif size_type find_last_not_of(const CharT* s, size_type pos, size_type count) const; size_type find_last_not_of(const CharT* s, size_type pos = npos) const; size_type find_last_not_of(CharT ch, size_type pos = npos) const; @@ -433,6 +593,9 @@ typedef std::basic_string wstring; typedef std::basic_string u16string; typedef std::basic_string u32string; #endif +#if CPPREFERENCE_STDVER >= 2020 +using u8string = std::basic_string; +#endif template basic_string @@ -590,26 +753,26 @@ std::basic_istream& getline(std::basic_istream&& i #endif #if CPPREFERENCE_STDVER>= 2011 -int stoi(const std::string& str, std::size_t* pos = 0, int base = 10); -int stoi(const std::wstring& str, std::size_t* pos = 0, int base = 10); - -long stol(const std::string& str, std::size_t* pos = 0, int base = 10); -long stol(const std::wstring& str, std::size_t* pos = 0, int base = 10); - -long long stoll(const std::string& str, std::size_t* pos = 0, int base = 10); -long long stoll(const std::wstring& str, std::size_t* pos = 0, int base = 10); - -unsigned long stoul(const std::string& str, std::size_t* pos = 0, int base = 10); -unsigned long stoul(const std::wstring& str, std::size_t* pos = 0, int base = 10); -unsigned long long stoull(const std::string& str, std::size_t* pos = 0, int base = 10); -unsigned long long stoull(const std::wstring& str, std::size_t* pos = 0, int base = 10); - -float stof(const std::string& str, std::size_t* pos = 0); -float stof(const std::wstring& str, std::size_t* pos = 0); -double stod(const std::string& str, std::size_t* pos = 0); -double stod(const std::wstring& str, std::size_t* pos = 0); -long double stold(const std::string& str, std::size_t* pos = 0); -long double stold(const std::wstring& str, std::size_t* pos = 0); +int stoi(const std::string& str, std::size_t* pos = nullptr, int base = 10); +int stoi(const std::wstring& str, std::size_t* pos = nullptr, int base = 10); + +long stol(const std::string& str, std::size_t* pos = nullptr, int base = 10); +long stol(const std::wstring& str, std::size_t* pos = nullptr, int base = 10); + +long long stoll(const std::string& str, std::size_t* pos = nullptr, int base = 10); +long long stoll(const std::wstring& str, std::size_t* pos = nullptr, int base = 10); + +unsigned long stoul(const std::string& str, std::size_t* pos = nullptr, int base = 10); +unsigned long stoul(const std::wstring& str, std::size_t* pos = nullptr, int base = 10); +unsigned long long stoull(const std::string& str, std::size_t* pos = nullptr, int base = 10); +unsigned long long stoull(const std::wstring& str, std::size_t* pos = nullptr, int base = 10); + +float stof(const std::string& str, std::size_t* pos = nullptr); +float stof(const std::wstring& str, std::size_t* pos = nullptr); +double stod(const std::string& str, std::size_t* pos = nullptr); +double stod(const std::wstring& str, std::size_t* pos = nullptr); +long double stold(const std::string& str, std::size_t* pos = nullptr); +long double stold(const std::wstring& str, std::size_t* pos = nullptr); std::string to_string(int value); std::string to_string(long value); diff --git a/headers/string_view b/headers/string_view new file mode 100644 index 000000000..f9c0d50bb --- /dev/null +++ b/headers/string_view @@ -0,0 +1,213 @@ +/* Copyright (C) 2018 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_STRING_VIEW_H +#define CPPREFERENCE_STRING_VIEW_H + +#if CPPREFERENCE_STDVER >= 2017 + +#include // for std::reverse_iterator +#include + +namespace std { + +template*/> +class basic_string_view { +public: + using traits_type = Traits; + using value_type = CharT; + + using size_type = size_t; + using difference_type = ptrdiff_t; + using reference = const CharT&; + using const_reference = const CharT&; + using pointer = const CharT*; + using const_pointer = const CharT*; + + using const_iterator = const CharT*; + using iterator = const_iterator; + using const_reverse_iterator = std::reverse_iterator; + using reverse_iterator = const_reverse_iterator; + static const size_type npos = static_cast(-1); + + // [string.view.cons], construct/copy + + constexpr basic_string_view() noexcept; + constexpr basic_string_view( + const basic_string_view& other) noexcept = default; + + constexpr basic_string_view(const CharT* s) noexcept; + + constexpr basic_string_view(const CharT* s, size_type length) noexcept; + + constexpr basic_string_view& + operator=(const basic_string_view& other) noexcept = default; + + + constexpr const_iterator begin() const noexcept; + constexpr const_iterator cbegin() const noexcept; + + constexpr const_iterator end() const noexcept; + constexpr const_iterator cend() const noexcept; + + constexpr const_reverse_iterator rbegin() const noexcept; + constexpr const_reverse_iterator crbegin() const noexcept; + + constexpr const_reverse_iterator rend() const noexcept; + constexpr const_reverse_iterator crend() const noexcept; + + constexpr size_type size() const noexcept; + constexpr size_type length() const noexcept; + + constexpr size_type max_size() const noexcept; + constexpr bool empty() const noexcept; + + constexpr const CharT& operator[](size_type pos) const noexcept; + + constexpr const CharT& at(size_type pos) const; + + constexpr const CharT& front() const noexcept; + + constexpr const CharT& back() const noexcept; + + constexpr const CharT* data() const noexcept; + + constexpr void remove_prefix(size_type count) noexcept; + + constexpr void remove_suffix(size_type count) noexcept; + + constexpr void swap(basic_string_view& other) noexcept; + + size_type copy(CharT* str, size_type length, size_type pos = 0) const; + + constexpr basic_string_view substr(size_type pos, + size_type length = npos) const; + + constexpr int compare(basic_string_view str) const noexcept; + constexpr int compare(size_type pos1, size_type count1, + basic_string_view str) const; + constexpr int compare(size_type pos1, size_type count1, + basic_string_view str, + size_type pos2, size_type count2) const; + + constexpr int compare(const CharT* s) const noexcept; + constexpr int compare(size_type pos1, size_type count1, + const CharT* s) const; + constexpr int compare(size_type pos1, size_type count1, + const CharT* s, size_type count2) const; + + constexpr size_type find(basic_string_view str, + size_type pos = 0) const noexcept; + constexpr size_type find(CharT ch, size_type pos = 0) const noexcept; + constexpr size_type find(const CharT* s, + size_type pos, size_type count) const noexcept; + constexpr size_type find(const CharT* s, size_type pos = 0) const noexcept; + + constexpr size_type rfind(basic_string_view str, + size_type pos = npos) const noexcept; + constexpr size_type rfind(CharT ch, + size_type pos = npos) const noexcept; + constexpr size_type rfind(const CharT* s, + size_type pos, size_type count) const noexcept; + constexpr size_type rfind(const CharT* s, + size_type pos = npos) const noexcept; + + constexpr size_type find_first_of(basic_string_view str, + size_type pos = 0) const noexcept; + constexpr size_type find_first_of(CharT ch, size_type pos = 0) const noexcept; + constexpr size_type find_first_of(const CharT* s, + size_type pos, size_type count) const noexcept; + constexpr size_type find_first_of(const CharT* s, size_type pos = 0) const noexcept; + + constexpr size_type find_first_not_of(basic_string_view str, + size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(CharT ch, size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(const CharT* s, + size_type pos, size_type count) const noexcept; + constexpr size_type find_first_not_of(const CharT* s, size_type pos = 0) const noexcept; + + constexpr size_type find_last_of(basic_string_view str, + size_type pos = npos) const noexcept; + constexpr size_type find_last_of(CharT ch, size_type pos=npos) const noexcept; + constexpr size_type find_last_of(const CharT* s, size_type pos, + size_type count) const noexcept; + constexpr size_type find_last_of(const CharT* s, size_type pos = npos) const noexcept; + + constexpr size_type find_last_not_of(basic_string_view str, + size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(CharT ch, size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(const CharT* s, + size_type pos, size_type count) const noexcept; + constexpr size_type find_last_not_of(const CharT* s, + size_type pos = npos) const noexcept; +}; + +using string_view = basic_string_view; +using wstring_view = basic_string_view; +using u16string_view = basic_string_view; +using u32string_view = basic_string_view; + +template +constexpr bool +operator==(basic_string_view lhs, + basic_string_view rhs) noexcept; + +template +constexpr bool +operator!=(basic_string_view lhs, + basic_string_view rhs) noexcept; + +template +constexpr bool +operator<(basic_string_view lhs, + basic_string_view rhs) noexcept; + +template +constexpr bool +operator<=(basic_string_view lhs, + basic_string_view rhs) noexcept; + +template +constexpr bool +operator>(basic_string_view lhs, + basic_string_view rhs) noexcept; + +template +constexpr bool +operator>=(basic_string_view lhs, + basic_string_view rhs) noexcept; + +inline namespace literals { +inline namespace string_view_literals { + +constexpr string_view operator "" sv(const char* str, size_t len) noexcept; + +#if CPPREFERENCE_STDVER >= 2020 +constexpr u8string_view + operator "" sv(const char8_t* str, size_t len) noexcept; +#endif + +constexpr u16string_view operator "" sv(const char16_t* str, size_t len) noexcept; +constexpr u32string_view operator "" sv(const char32_t* str, size_t len) noexcept; +constexpr wstring_view operator "" sv(const wchar_t* str, size_t len) noexcept; + +} // namespace string_view_literals +} // namespace literals + +} // namespace std + +#endif // CPPREFERENCE_STDVER >= 2017 + +#endif // CPPREFERENCE_STRING_VIEW_H diff --git a/headers/system_error b/headers/system_error index 53848016d..68d8d0dc6 100644 --- a/headers/system_error +++ b/headers/system_error @@ -18,8 +18,15 @@ #if CPPREFERENCE_STDVER>= 2011 +#include +#include // for integral_constant +#include // for runtime_error + namespace std { +class error_condition; +class error_code; + class error_category { public: error_category(const error_category& other) = delete; diff --git a/headers/thread b/headers/thread index 45a9ae672..8aca56cfb 100644 --- a/headers/thread +++ b/headers/thread @@ -18,6 +18,9 @@ #if CPPREFERENCE_STDVER>= 2011 +#include +#include + namespace std { class thread { diff --git a/headers/tuple b/headers/tuple index 42be3583d..0e4520ee7 100644 --- a/headers/tuple +++ b/headers/tuple @@ -18,127 +18,145 @@ #if CPPREFERENCE_STDVER >= 2011 +#include // for size_t +#include // for allocator_arg_t #include // for std::pair +#include // for integral_constant namespace std { -template +template class tuple { public: constexpr tuple(); - template + template explicit tuple(UTypes&& ... args); - template + template tuple(const tuple& other); template tuple(tuple&& other); - template + template tuple(const pair& p); - template + template tuple(pair&& p); tuple(const tuple& other) = default; tuple(tuple&& other) = default; - template + template tuple(std::allocator_arg_t, const Alloc& a); - template + template tuple(std::allocator_arg_t, const Alloc& a, const Types& ... args); - template + template tuple(std::allocator_arg_t, const Alloc& a, UTypes&& ... args); template tuple(std::allocator_arg_t, const Alloc& a, const tuple& other); - template + template tuple(std::allocator_arg_t, const Alloc& a, tuple&& other); - template + template tuple(std::allocator_arg_t, const Alloc& a, const pair& p); - template + template tuple(std::allocator_arg_t, const Alloc& a, pair&& p); - template + template tuple(std::allocator_arg_t, const Alloc& a, const tuple& other); - template + template tuple(std::allocator_arg_t, const Alloc& a, tuple&& other); tuple& operator=(const tuple& other); tuple& operator=(tuple&& other); - template + template tuple& operator=(const tuple& other); - template + template tuple& operator=(tuple&& other); - template + template tuple& operator=(const pair& p); - template + template tuple& operator=(pair&& p); void swap(tuple& other); }; -template -tuple make_tuple(Types&& ... args); +template +struct tuple_size > : std::integral_constant { }; -template +#if CPPREFERENCE_SIMPLIFY_TYPEDEFS +template +struct tuple_element > { + typedef void type; +}; +#else +template +struct tuple_element; + +template +struct tuple_element<0, tuple > { + using type = T; +}; + +template +struct tuple_element > { + using type = typename tuple_element::type; +}; +#endif + +template +tuple make_tuple(Types&& ... args); + +template tuple tie(Types& ... args); -template -tuple < Types&& ... > forward_as_tuple(Types&& ... args); +template +tuple forward_as_tuple(Types&& ... args); -template +template std::tuple tuple_cat(Tuples&& ... args); -template +template typename std::tuple_element >::type& -get(tuple& t); + get(tuple& t); -template +template typename std::tuple_element >::type&& -get(tuple&& t); + get(tuple&& t); -template +template typename std::tuple_element >::type const& -get(const tuple& t); + get(const tuple& t); -template +template bool operator==(const tuple& lhs, const tuple& rhs); -template +template bool operator!=(const tuple& lhs, const tuple& rhs); -template +template bool operator<(const tuple& lhs, const tuple& rhs); -template +template bool operator<=(const tuple& lhs, const tuple& rhs); -template +template bool operator>(const tuple& lhs, const tuple& rhs); -template +template bool operator>=(const tuple& lhs, const tuple& rhs); -template +template void swap(tuple& lhs, tuple& rhs); -template -class tuple_size > : public std::integral_constant { }; - -template -class tuple_element > { - typedef void type; -}; // SIMPLIFIED - const void* ignore; // SIMPLIFIED } // namespace std diff --git a/headers/type_traits b/headers/type_traits index a2d298919..acb197287 100644 --- a/headers/type_traits +++ b/headers/type_traits @@ -18,6 +18,8 @@ #if CPPREFERENCE_STDVER>= 2011 +#include // for size_t + namespace std { template @@ -25,14 +27,19 @@ struct integral_constant { typedef T value_type; typedef integral_constant type; - static constexpr T value; + static constexpr T value = v; constexpr operator value_type() const; - constexpr operator()() const; + constexpr T operator()() const; }; typedef integral_constant false_type; typedef integral_constant true_type; +#if CPPREFERENCE_STDVER >= 2017 +template +using bool_constant = integral_constant; +#endif + // SIMPLIFIED: the actual base type depends on T // primary type categories template struct is_void : integral_constant {}; @@ -52,6 +59,23 @@ template struct is_rvalue_reference : integral_constant {} template struct is_member_object_pointer : integral_constant {}; template struct is_member_function_pointer : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_void_v = false; +template inline constexpr bool is_null_pointer_v = false; +template inline constexpr bool is_integral_v = false; +template inline constexpr bool is_floating_point_v = false; +template inline constexpr bool is_array_v = false; +template inline constexpr bool is_enum_v = false; +template inline constexpr bool is_union_v = false; +template inline constexpr bool is_class_v = false; +template inline constexpr bool is_function_v = false; +template inline constexpr bool is_pointer_v = false; +template inline constexpr bool is_lvalue_reference_v = false; +template inline constexpr bool is_rvalue_reference_v = false; +template inline constexpr bool is_member_object_pointer_v = false; +template inline constexpr bool is_member_function_pointer_v = false; +#endif + // composite type categories template struct is_fundamental : integral_constant {}; template struct is_arithmetic : integral_constant {}; @@ -61,6 +85,16 @@ template struct is_compound : integral_constant {}; template struct is_reference : integral_constant {}; template struct is_member_pointer : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_fundamental_v = false; +template inline constexpr bool is_arithmetic_v = false; +template inline constexpr bool is_scalar_v = false; +template inline constexpr bool is_object_v = false; +template inline constexpr bool is_compound_v = false; +template inline constexpr bool is_reference_v = false; +template inline constexpr bool is_member_pointer_v = false; +#endif + // type properties template struct is_const : integral_constant {}; template struct is_volatile : integral_constant {}; @@ -71,138 +105,346 @@ template struct is_pod : integral_constant {}; template struct is_literal_type : integral_constant {}; template struct is_empty : integral_constant {}; template struct is_polymorphic : integral_constant {}; -#if CPPREFERENCE_STDVER>= 2014` +#if CPPREFERENCE_STDVER >= 2014 template struct is_final : integral_constant {}; #endif template struct is_abstract : integral_constant {}; template struct is_signed : integral_constant {}; template struct is_unsigned : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_const_v = false; +template inline constexpr bool is_volatile_v = false; +template inline constexpr bool is_trivial_v = false; +template inline constexpr bool is_trivially_copyable_v = false; +template inline constexpr bool is_standard_layout_v = false; +template inline constexpr bool is_pod_v = false; +template inline constexpr bool is_literal_type_v = false; +template inline constexpr bool is_empty_v = false; +template inline constexpr bool is_polymorphic_v = false; +template inline constexpr bool is_final_v = false; +template inline constexpr bool is_abstract_v = false; +template inline constexpr bool is_signed_v = false; +template inline constexpr bool is_unsigned_v = false; +#endif + // supported operations template struct is_constructible : integral_constant {}; template struct is_trivially_constructible : integral_constant {}; template struct is_nothrow_constructible : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_constructible_v = false; +template inline constexpr bool is_trivially_constructible_v = false; +template inline constexpr bool is_nothrow_constructible_v = false; +#endif + template struct is_default_constructible : integral_constant {}; template struct is_trivially_default_constructible : integral_constant {}; template struct is_nothrow_default_constructible : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_default_constructible_v = false; +template inline constexpr bool is_trivially_default_constructible_v = false; +template inline constexpr bool is_nothrow_default_constructible_v = false; +#endif + template struct is_copy_constructible : integral_constant {}; template struct is_trivially_copy_constructible : integral_constant {}; template struct is_nothrow_copy_constructible : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_copy_constructible_v = false; +template inline constexpr bool is_trivially_copy_constructible_v = false; +template inline constexpr bool is_nothrow_copy_constructible_v = false; +#endif + template struct is_move_constructible : integral_constant {}; template struct is_trivially_move_constructible : integral_constant {}; template struct is_nothrow_move_constructible : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_move_constructible_v = false; +template inline constexpr bool is_trivially_move_constructible_v = false; +template inline constexpr bool is_nothrow_move_constructible_v = false; +#endif + template struct is_assignable : integral_constant {}; template struct is_trivially_assignable : integral_constant {}; template struct is_nothrow_assignable : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_assignable_v = false; +template inline constexpr bool is_trivially_assignable_v = false; +template inline constexpr bool is_nothrow_assignable_v = false; +#endif + template struct is_copy_assignable : integral_constant {}; template struct is_trivially_copy_assignable : integral_constant {}; template struct is_nothrow_copy_assignable : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_copy_assignable_v = false; +template inline constexpr bool is_trivially_copy_assignable_v = false; +template inline constexpr bool is_nothrow_copy_assignable_v = false; +#endif + template struct is_move_assignable : integral_constant {}; template struct is_trivially_move_assignable : integral_constant {}; template struct is_nothrow_move_assignable : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_move_assignable_v = false; +template inline constexpr bool is_trivially_move_assignable_v = false; +template inline constexpr bool is_nothrow_move_assignable_v = false; +#endif + template struct is_destructible : integral_constant {}; template struct is_trivially_destructible : integral_constant {}; template struct is_nothrow_destructible : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_destructible_v = false; +template inline constexpr bool is_trivially_destructible_v = false; +template inline constexpr bool is_nothrow_destructible_v = false; +#endif + template struct has_virtual_destructor : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool has_virtual_destructor_v = false; +#endif + // property queries template struct alignment_of : integral_constant {}; template struct rank : integral_constant {}; template struct extent : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr size_t alignment_of_v = 0; +template inline constexpr size_t rank_v = 0; +template inline constexpr size_t extent_v = 0; +#endif + // type relationships template struct is_same : integral_constant {}; template struct is_base_of : integral_constant {}; template struct is_convertible : integral_constant {}; +#if CPPREFERENCE_STDVER >= 2014 +template inline constexpr bool is_same_v = false; +template inline constexpr bool is_base_of_v = false; +template inline constexpr bool is_convertible_v = false; +#endif + // const-volatility specifiers template struct remove_cv { - typedef T type; + typedef T type; // SIMPLIFIED type }; template struct remove_const { - typedef T type; + typedef T type; // SIMPLIFIED type }; template struct remove_volatile { - typedef T type; + typedef T type; // SIMPLIFIED type }; + +#if CPPREFERENCE_STDVER >= 2014 +template +using remove_cv_t = T; // SIMPLIFIED typedef +template +using remove_const_t = T; // SIMPLIFIED typedef +template +using remove_volatile_t = T; // SIMPLIFIED typedef +#endif + template struct add_cv { - typedef T type; + typedef T type; // SIMPLIFIED type }; template struct add_const { - typedef T type; + typedef T type; // SIMPLIFIED type }; template struct add_volatile { - typedef T type; + typedef T type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using add_cv_t = T; // SIMPLIFIED typedef +template +using add_const_t = T; // SIMPLIFIED typedef +template +using add_volatile_t = T; // SIMPLIFIED typedef +#endif + // references template struct remove_reference { typedef T type; }; -template struct add_lvalue_reference { +template struct remove_reference { typedef T type; }; -template struct add_rvalue_reference { +template struct remove_reference { typedef T type; }; +template struct add_lvalue_reference { + typedef T type; // SIMPLIFIED type +}; +template struct add_rvalue_reference { + typedef T type; // SIMPLIFIED type +}; + +#if CPPREFERENCE_STDVER >= 2014 +template +using remove_reference_t = T; // SIMPLIFIED typedef +template +using add_lvalue_reference_t = T; // SIMPLIFIED typedef +template +using add_rvalue_reference_t = T; // SIMPLIFIED typedef +#endif + // pointers template struct remove_pointer { - typedef T type; + typedef T type; // SIMPLIFIED type }; template struct add_pointer { - typedef T type; + typedef T* type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using remove_pointer_t = T; // SIMPLIFIED typedef +template +using add_pointer_t = T*; // SIMPLIFIED typedef +#endif + // sign modifiers template struct make_signed { - typedef T type; + typedef T type; // SIMPLIFIED type }; template struct make_unsigned { - typedef T type; + typedef T type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using make_signed_t = T; // SIMPLIFIED typedef +template +using make_unsigned_t = T; // SIMPLIFIED typedef +#endif + // arrays template struct remove_extent { - typedef T type; + typedef T type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using remove_extent_t = T; // SIMPLIFIED typedef +#endif + template struct remove_all_extents { - typedef T type; + typedef T type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using remove_all_extents_t = T; // SIMPLIFIED typedef +#endif // miscellaneous transformations template struct aligned_storage { - typedef int type; + typedef int type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using aligned_storage_t = int; // SIMPLIFIED typedef +#endif + template struct aligned_union { - typedef int type; + typedef int type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using aligned_union_t = int; // SIMPLIFIED typedef +#endif + template struct decay { - typedef int type; + typedef T type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using decay_t = T; // SIMPLIFIED typedef +#endif + +#if CPPREFERENCE_SIMPLIFY_TYPEDEFS + template struct enable_if { - typedef int type; + typedef int type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using enable_if_t = int; // SIMPLIFIED typedef +#endif + +#else + +template struct enable_if {}; + +template +struct enable_if { + typedef T type; +}; +#if CPPREFERENCE_STDVER >= 2014 +template +using enable_if_t = typename enable_if::type; +#endif + +#endif // CPPREFERENCE_SIMPLIFY_TYPEDEFS + template struct conditional { - typedef int type; + typedef int type; // SIMPLIFIED type }; +#if CPPREFERENCE_STDVER >= 2014 +template +using conditional_t = int; // SIMPLIFIED typedef +#endif + template struct common_type { typedef int type; }; +#if CPPREFERENCE_STDVER >= 2014 +template +using common_type_t = int; +#endif + template struct underlying_type { - typedef int type; + typedef int type; // SIMPLIFIED type }; -template class result_of { +#if CPPREFERENCE_STDVER >= 2014 +template +using underlying_type_t = int; // SIMPLIFIED typedef +#endif + +#if CPPREFERENCE_STDVER < 2020 +template +class result_of { + typedef int type; +}; // SIMPLIFIED: removed specializations +#endif + +#if CPPREFERENCE_STDVER >= 2014 && CPPREFERENCE_STDVER < 2020 +template +using result_of_t = int; // SIMPLIFIED typedef +#endif + +#if CPPREFERENCE_STDVER >= 2017 +template +class invoke_result { typedef int type; -}; // SIMPLIFIED: removed specializatio +}; // SIMPLIFIED: removed specializations + +template +using invoke_result_t = int; // SIMPLIFIED typedef +#endif } // namespace std diff --git a/headers/typeindex b/headers/typeindex index f76d2a0e2..405117a7c 100644 --- a/headers/typeindex +++ b/headers/typeindex @@ -17,6 +17,7 @@ #define CPPREFERENCE_TYPEINDEX_H #if CPPREFERENCE_STDVER>= 2011 +#include // for size_t #include namespace std { diff --git a/headers/typeinfo b/headers/typeinfo index 65f865c0e..68b5293a7 100644 --- a/headers/typeinfo +++ b/headers/typeinfo @@ -16,6 +16,7 @@ #ifndef CPPREFERENCE_TYPEINFO_H #define CPPREFERENCE_TYPEINFO_H +#include // for size_t #include namespace std { diff --git a/headers/unordered_map b/headers/unordered_map index b1fc53c42..93f102083 100644 --- a/headers/unordered_map +++ b/headers/unordered_map @@ -20,6 +20,7 @@ #include #include // for size_t, ptrdiff_t +#include // for hash #include // for std::reverse_iterator #include // for std::allocator #include // for std::pair @@ -56,6 +57,9 @@ public: typedef value_type* local_iterator; // actual type is unspecified typedef const value_type* const_local_iterator; // actual type is unspecified + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + // constructor // constructor #if CPPREFERENCE_STDVER <2014 @@ -107,7 +111,7 @@ public: unordered_map(unordered_map&& other, const Allocator& alloc); unordered_map(std::initializer_list init, - size_type bucket_count = /*implementation-defined*/, + size_type bucket_count = /*implementation-defined*/0, const Hash& hash = Hash(), const KeyEqual& equal = KeyEqual(), const Allocator& alloc = Allocator()); @@ -179,12 +183,40 @@ public: void insert(std::initializer_list ilist); +#if CPPREFERENCE_STDVER >= 2017 + template + std::pair insert_or_assign(const Key& key, M&& obj); + + template + std::pair insert_or_assign(Key&& key, M&& obj); + + template + iterator insert_or_assign(const_iterator hint, const Key& key, M&& obj); + + template + iterator insert_or_assign(const_iterator hint, Key&& key, M&& obj); +#endif + template std::pair emplace(Args&& ... args); template iterator emplace_hint(const_iterator hint, Args&& ... args); +#if CPPREFERENCE_STDVER >= 2017 + template + std::pair try_emplace(const Key& key, Args&& ... args); + + template + std::pair try_emplace(Key&& key, Args&& ... args); + + template + std::pair try_emplace(const_iterator hint, const Key& key, Args&& ... args); + + template + std::pair try_emplace(const_iterator hint, Key&& key, Args&& ... args); +#endif + iterator erase(const_iterator pos); iterator erase(const_iterator first, const_iterator last); size_type erase(const key_type& key); @@ -266,6 +298,9 @@ public: typedef T* local_iterator; // actual type is unspecified typedef const T* const_local_iterator; // actual type is unspecified + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + // constructor // constructor #if CPPREFERENCE_STDVER <2014 @@ -317,7 +352,7 @@ public: unordered_multimap(unordered_multimap&& other, const Allocator& alloc); unordered_multimap(std::initializer_list init, - size_type bucket_count = /*implementation-defined*/, + size_type bucket_count = /*implementation-defined*/0, const Hash& hash = Hash(), const KeyEqual& equal = KeyEqual(), const Allocator& alloc = Allocator()); diff --git a/headers/unordered_set b/headers/unordered_set index d4f9799bb..51f1086da 100644 --- a/headers/unordered_set +++ b/headers/unordered_set @@ -20,6 +20,7 @@ #include #include // for size_t, ptrdiff_t +#include // for hash #include // for std::allocator #include // for std::pair @@ -103,7 +104,7 @@ public: unordered_set(unordered_set&& other, const Allocator& alloc); unordered_set(std::initializer_list init, - size_type bucket_count = /*implementation-defined*/, + size_type bucket_count = /*implementation-defined*/0, const Hash& hash = Hash(), const KeyEqual& equal = KeyEqual(), const Allocator& alloc = Allocator()); @@ -237,10 +238,10 @@ public: typedef typename std::allocator_traits::pointer pointer; typedef typename std::allocator_traits::const_pointer const_pointer; #endif - typedef T* iterator; // actual type is unspecified - typedef const T* const_iterator; // actual type is unspecified - typedef T* local_iterator; // actual type is unspecified - typedef const T* const_local_iterator; // actual type is unspecified + typedef Key* iterator; // actual type is unspecified + typedef const Key* const_iterator; // actual type is unspecified + typedef Key* local_iterator; // actual type is unspecified + typedef const Key* const_local_iterator; // actual type is unspecified // constructor @@ -294,7 +295,7 @@ public: unordered_multiset(unordered_multiset&& other, const Allocator& alloc); unordered_multiset(std::initializer_list init, - size_type bucket_count = /*implementation-defined*/, + size_type bucket_count = /*implementation-defined*/0, const Hash& hash = Hash(), const KeyEqual& equal = KeyEqual(), const Allocator& alloc = Allocator()); @@ -408,3 +409,5 @@ void swap(unordered_multiset& lhs, } // namespace std #endif // CPPREFERENCE_STDVER>= 2011 + +#endif // CPPREFERENCE_UNORDERED_SET_H diff --git a/headers/utility b/headers/utility index 134492439..55dd9b965 100644 --- a/headers/utility +++ b/headers/utility @@ -20,6 +20,9 @@ #include #endif +#include // for size_t +#include // for remove_reference + namespace std { #if CPPREFERENCE_STDVER>= 2011 @@ -42,62 +45,143 @@ template bool operator>=(const T& lhs, const T& rhs); } // namespace rel_ops -#if CPPREFERENCE_STDVER>= 2014 +#if CPPREFERENCE_STDVER >= 2020 +template +constexpr T exchange(T& obj, U && new_value); +#elif CPPREFERENCE_STDVER >= 2014 template T exchange(T& obj, U && new_value); #endif -#if CPPREFERENCE_STDVER>= 2011 +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr T&& forward(typename std::remove_reference::type& t); + +template +constexpr T&& forward(typename std::remove_reference::type&& t); +#elif CPPREFERENCE_STDVER >= 2011 template T&& forward(typename std::remove_reference::type& t); template T&& forward(typename std::remove_reference::type&& t); +#endif +#if CPPREFERENCE_STDVER >= 2014 +template +#if CPPREFERENCE_SIMPLIFY_TYPEDEFS +constexpr T&& move(T&& t); +#else +constexpr typename remove_reference::type&& move(T&& t); +#endif +#elif CPPREFERENCE_STDVER >= 2011 +#if CPPREFERENCE_SIMPLIFY_TYPEDEFS template -typename T&& move(T&& t); // SIMPLIFIED: return type +T&& move(T&& t); +#else +template +typename remove_reference::type&& move(T&& t); +#endif +#endif +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr T&& move_if_noexcept(T&& t); // SIMPLIFIED: return type +#elif CPPREFERENCE_STDVER >= 2011 template -typename T&& move_if_noexcept(T&& t); // SIMPLIFIED: return type +T&& move_if_noexcept(T&& t); // SIMPLIFIED: return type +#endif +#if CPPREFERENCE_STDVER >= 2011 template T declval(); // SIMPLIFIED: return type +#endif +#if CPPREFERENCE_STDVER >= 2011 struct piecewise_construct_t { }; constexpr piecewise_construct_t piecewise_construct; #endif +#if CPPREFERENCE_STDVER >= 2017 +struct in_place_t {}; +inline constexpr in_place_t in_place; + +template +struct in_place_type_t{}; + +template +inline constexpr in_place_type_t in_place_type; + +template +struct in_place_index_t; + +template +inline constexpr in_place_index_t in_place_index; +#endif + +template class tuple; + template < class T1, class T2 - > struct pair { +> struct pair { typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; +#if CPPREFERENCE_STDVER >= 2011 + constexpr pair(); +#else pair(); +#endif + +#if CPPREFERENCE_STDVER >= 2014 + constexpr pair(const T1& x, const T2& y); + + template + constexpr pair(const pair& p); + + constexpr pair(const pair& p); +#else pair(const T1& x, const T2& y); template pair(const pair& p); -#if CPPREFERENCE_STDVER>= 2011 + pair(const pair& p); +#endif + +#if CPPREFERENCE_STDVER >= 2014 + template + constexpr pair(U1&& x, U2&& y); + + template + constexpr pair(pair&& p); + + constexpr pair(pair&& p); +#elif CPPREFERENCE_STDVER >= 2011 template pair(U1&& x, U2&& y); template pair(pair&& p); + pair(pair&& p); +#endif + +#if CPPREFERENCE_STDVER >= 2020 + template + constexpr pair(std::piecewise_construct_t, + std::tuple first_args, + std::tuple second_args); +#elif CPPREFERENCE_STDVER >= 2011 template pair(std::piecewise_construct_t, std::tuple first_args, std::tuple second_args); #endif - pair(const pair& p); - pair(pair&& p); - pair& operator=(const pair& other); template @@ -113,6 +197,20 @@ template < void swap(pair& other); }; +#if CPPREFERENCE_STDVER >= 2014 +template +constexpr bool operator==(const pair& lhs, const pair& rhs); +template +constexpr bool operator!=(const pair& lhs, const pair& rhs); +template +constexpr bool operator<(const pair& lhs, const pair& rhs); +template +constexpr bool operator<=(const pair& lhs, const pair& rhs); +template +constexpr bool operator>(const pair& lhs, const pair& rhs); +template +constexpr bool operator>=(const pair& lhs, const pair& rhs); +#else template bool operator==(const pair& lhs, const pair& rhs); template @@ -125,25 +223,58 @@ template bool operator>(const pair& lhs, const pair& rhs); template bool operator>=(const pair& lhs, const pair& rhs); +#endif -#if CPPREFERENCE_STDVER <2011 +#if CPPREFERENCE_STDVER >= 2014 template -std::pair make_pair(T1 t, T2 u); -#else +constexpr std::pair make_pair(T1&& t, T2&& u); +#elif CPPREFERENCE_STDVER >= 2011 template std::pair make_pair(T1&& t, T2&& u); +#else +template +std::pair make_pair(T1 t, T2 u); #endif template void swap(pair& lhs, pair& rhs); #if CPPREFERENCE_STDVER>= 2011 +template +struct tuple_element; + +template +struct tuple_element<0, std::pair> { using type = T1; }; +template +struct tuple_element<1, std::pair> { using type = T2; }; + template -typename std::tuple_element>::type& +typename tuple_element>::type& get(pair& p); + +template +const typename tuple_element>::type& + get(const pair& p); + +template +typename tuple_element>::type&& + get(pair&& p); + +template +const typename tuple_element>::type&& + get(const pair&& p); + // SIMPLIFIED: additional overloads omitted #endif +#if CPPREFERENCE_STDVER >= 2014 +template +struct tuple_size; + +template +struct tuple_size > : public std::integral_constant { }; +#endif + } // namespace std #endif // CPPREFERENCE_UTILITY_H diff --git a/headers/valarray b/headers/valarray index 4b61f6f6c..3b407b7a2 100644 --- a/headers/valarray +++ b/headers/valarray @@ -20,8 +20,17 @@ #include // for std::initializer_list #endif +#include + namespace std { +template class slice_array; +template class gslice_array; +template class mask_array; +template class indirect_array; +class slice; +class gslice; + template class valarray { public: @@ -50,16 +59,19 @@ public: valarray& operator=(valarray&& other); #endif valarray& operator=(const T& val); - valarray& operator=(const std::slice_array& other); - valarray& operator=(const std::gslice_array& other); - valarray& operator=(const std::mask_array& other); - valarray& operator=(const std::indirect_array& other); + valarray& operator=(const std::slice_array& other); + valarray& operator=(const std::gslice_array& other); + valarray& operator=(const std::mask_array& other); + valarray& operator=(const std::indirect_array& other); #if CPPREFERENCE_STDVER>= 2011 valarray& operator=(std::initializer_list il); #endif +#if CPPREFERENCE_STDVER>= 2011 T operator[](std::size_t pos) const; +#else const T& operator[](std::size_t pos) const; +#endif T& operator[](std::size_t pos); std::valarray operator[](std::slice slicearr) const; std::slice_array operator[](std::slice slicearr); diff --git a/headers/variant b/headers/variant new file mode 100644 index 000000000..fed65ff7d --- /dev/null +++ b/headers/variant @@ -0,0 +1,228 @@ +/* Copyright (C) 2019 Povilas Kanapickas + + This file is part of cppreference-doc + + This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 + Unported License. To view a copy of this license, visit + http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative + Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.3 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +*/ + +#ifndef CPPREFERENCE_VARIANT_H +#define CPPREFERENCE_VARIANT_H + +#if CPPREFERENCE_STDVER >= 2017 + +#include // exception +#include // hash +#include // in_place_type_t, ... +#include +#include + +namespace std { + +inline constexpr std::size_t variant_npos = static_cast(-1); + +struct monostate {}; + +class bad_variant_access : public exception { +public: + bad_variant_access(); + ~bad_variant_access() override; + const char * what() const override; +}; + +template +class variant; // forward declaration + +template +struct variant_alternative; // undefined + +template +struct variant_alternative> { + using type = CPPREFERENCE_SIMPLIFIED_TYPE; +}; + +template +struct variant_alternative> { + using type = CPPREFERENCE_SIMPLIFIED_TYPE; +}; + +template +struct variant_alternative> { + using type = CPPREFERENCE_SIMPLIFIED_TYPE; +}; + +template +struct variant_alternative> { + using type = CPPREFERENCE_SIMPLIFIED_TYPE; +}; + +template +using variant_alternative_t = typename variant_alternative::type; + + +template +class variant { +public: + constexpr variant(); + + constexpr variant(const variant& other); + + constexpr variant(variant&& other); + + template + constexpr variant(T&& t); + + template + constexpr explicit variant(in_place_type_t, Args&&... args); + + template + + constexpr explicit variant(in_place_type_t, + initializer_list il, Args&&... args); + + template + constexpr explicit variant(in_place_index_t, Args&&... args); + + template + constexpr explicit variant(in_place_index_t, + initializer_list il, Args&&... args); + + ~variant(); + + constexpr variant& operator=(const variant& rhs); + + constexpr variant& operator=(variant&& rhs); + + template + variant& operator=(T&& t); + + constexpr size_t index() const; + + constexpr bool valueless_by_exception() const; + + template + T& emplace(Args&&... args); + + template + T& emplace(initializer_list il, Args&&... args); + + template + variant_alternative_t& emplace(Args&&... args); + + template + variant_alternative_t& + emplace(initializer_list il, Args&&... args); + + void swap(variant& rhs); +}; + +template +constexpr bool operator==(const variant& v, const variant& w); + +template +constexpr bool operator!=(const variant& v, const variant& w); + +template +constexpr bool operator<(const variant& v, const variant& w); + +template +constexpr bool operator>(const variant& v, const variant& w); + +template +constexpr bool operator<=(const variant& v, const variant& w); + +template +constexpr bool operator>=(const variant& v, const variant& w); + +template +void swap(variant& lhs, variant& rhs); + +template +constexpr CPPREFERENCE_SIMPLIFIED_TYPE visit(Visitor&& vis, Variants&&... vars); + +template +constexpr R visit(Visitor&&, Variants&&...); + +template +constexpr bool holds_alternative(const variant& v); + +template +constexpr variant_alternative_t>& + get(variant& v); + +template +constexpr variant_alternative_t>&& + get(variant&& v); + +template +constexpr const variant_alternative_t>& + get(const variant& v); + +template +constexpr const variant_alternative_t>& + get(const variant&& v); + +template +constexpr T& get(variant& v); + +template +constexpr T&& get(variant&& v); + +template +constexpr const T& get(const variant& v); + +template +constexpr const T&& get(const variant&& v); + +template + +constexpr add_pointer_t>> + get_if(variant* pv); + +template +constexpr add_pointer_t>> + get_if(const variant* pv); + +template +constexpr add_pointer_t get_if(variant* pv); +template +constexpr add_pointer_t get_if(const variant* pv); + +template +struct variant_size; // undefined + +template +struct variant_size> : + integral_constant { +}; + +template +struct variant_size> : + integral_constant { +}; + +template +struct variant_size> : + integral_constant { +}; + +template +struct variant_size> : + integral_constant { +}; + + +template +struct hash> {}; + +} // namespace std + +#endif // CPPREFERENCE_STDVER >= 2017 +#endif // CPPREFERENCE_VARIANT_H diff --git a/headers/vector b/headers/vector index 5b2836e6c..e02f352f0 100644 --- a/headers/vector +++ b/headers/vector @@ -18,7 +18,7 @@ #if CPPREFERENCE_STDVER >= 2011 #include -#endif` +#endif #include // for size_t, ptrdiff_t #include // for std::reverse_iterator @@ -191,7 +191,10 @@ public: void push_back(T&& value); #endif -#if CPPREFERENCE_STDVER>= 2011 +#if CPPREFERENCE_STDVER >= 2017 + template + reference emplace_back(Args&& ... args); +#elif CPPREFERENCE_STDVER >= 2011 template void emplace_back(Args&& ... args); #endif diff --git a/images/math-atan2.py b/images/math-atan2.py index d1e02cf01..3679f4c3c 100644 --- a/images/math-atan2.py +++ b/images/math-atan2.py @@ -17,14 +17,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. +import math +import os +import pprint + import matplotlib.cm as cm import matplotlib.colors as colors import matplotlib.pyplot as plt - -import os import numpy as np -import math -import pprint font = {'family' : 'DejaVu Sans', 'weight' : 'normal', diff --git a/images/math.py b/images/math.py index 99b929e9f..6fee22734 100644 --- a/images/math.py +++ b/images/math.py @@ -16,11 +16,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. -import matplotlib.pyplot as plt import os -from numpy import * from bisect import * +import matplotlib.pyplot as plt +from numpy import * + # # DATA - array of items describing data to plot # Each item consists of the following parts diff --git a/index-chapters-c.xml b/index-chapters-c.xml index 7ed4dffe1..f45bb438d 100644 --- a/index-chapters-c.xml +++ b/index-chapters-c.xml @@ -20,6 +20,7 @@ + @@ -29,7 +30,7 @@ - + @@ -38,4 +39,5 @@ + diff --git a/index-chapters-cpp.xml b/index-chapters-cpp.xml index 7802cb588..e62d4a448 100644 --- a/index-chapters-cpp.xml +++ b/index-chapters-cpp.xml @@ -14,12 +14,13 @@ Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. --> - + + @@ -27,6 +28,7 @@ + @@ -34,8 +36,11 @@ + + + @@ -79,11 +84,13 @@ + + @@ -91,6 +98,7 @@ + @@ -103,22 +111,33 @@ + + + + + + - - + + + + + + + @@ -138,14 +157,19 @@ + + + + + @@ -162,10 +186,15 @@ + + + + + diff --git a/index-cpp-search-app.txt b/index-cpp-search-app.txt index 0125baa38..08c6c8b75 100644 --- a/index-cpp-search-app.txt +++ b/index-cpp-search-app.txt @@ -63,6 +63,7 @@ Pointers => cpp/language/pointer Arrays => cpp/language/array Enumerations and enumerators => cpp/language/enum const/volatile => cpp/language/cv +consteval specifier => cpp/language/consteval constexpr specifier => cpp/language/constexpr decltype operator => cpp/language/decltype auto specifier => cpp/language/auto @@ -210,6 +211,7 @@ bool type => cpp/language/types#Boolean_type case label => cpp/language/switch default label => cpp/language/switch type char => cpp/language/types +char8_t type => cpp/language/types#Character_types char16_t type => cpp/language/types#Character_types char32_t type => cpp/language/types#Character_types compl keyword => cpp/language/operator_alternative @@ -263,5 +265,11 @@ using (type alias, alias template) => cpp/language/type_alias ODR => cpp/language/definition#One_Definition_Rule odr-use => cpp/language/definition#One_Definition_Rule __has_include => cpp/preprocessor/include +__has_cpp_attribute => cpp/feature_test final => cpp/language/final override => cpp/language/override +type byte => cpp/types/byte +feature test => cpp/feature_test +keyword co_await => cpp/language/coroutines +keyword co_return => cpp/language/coroutines +keyword co_yield => cpp/language/coroutines diff --git a/index-functions-c.xml b/index-functions-c.xml index 40f45c556..da9847b6a 100644 --- a/index-functions-c.xml +++ b/index-functions-c.xml @@ -31,7 +31,6 @@ - @@ -126,7 +125,7 @@ - + @@ -141,7 +140,7 @@ - + @@ -156,7 +155,7 @@ - + @@ -171,7 +170,7 @@ - + @@ -186,7 +185,7 @@ - + @@ -201,7 +200,7 @@ - + @@ -216,7 +215,7 @@ - + @@ -231,7 +230,7 @@ - + @@ -246,7 +245,7 @@ - + @@ -261,7 +260,7 @@ - + @@ -276,22 +275,7 @@ - - - - - - - - - - - - - - - - + @@ -1094,8 +1078,8 @@ - - + + diff --git a/index-functions-cpp.xml b/index-functions-cpp.xml index 9e40f9ebd..3cd881ccc 100644 --- a/index-functions-cpp.xml +++ b/index-functions-cpp.xml @@ -28,10 +28,24 @@ - + - + + + + + + + + + + + + + + + @@ -123,7 +137,7 @@ - + @@ -138,7 +152,7 @@ - + @@ -153,7 +167,7 @@ - + @@ -168,7 +182,7 @@ - + @@ -183,7 +197,7 @@ - + @@ -198,7 +212,7 @@ - + @@ -213,7 +227,7 @@ - + @@ -228,7 +242,7 @@ - + @@ -243,7 +257,7 @@ - + @@ -258,7 +272,7 @@ - + @@ -273,22 +287,7 @@ - - - - - - - - - - - - - - - - + @@ -443,7 +442,7 @@ - + @@ -459,167 +458,179 @@ - + - + - + - - - + - + - + - + + + + + + + + + - + - + - + - + - - - - - - - - - - - - - + - - - + + + - + + + - + + + - + - + - + - + - + - + - + - + + + - + - + - - - + + + + + - + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - + + - - + + - + - + - + - + - + - + - + + + + + + + + + + + @@ -657,23 +668,32 @@ - + - + - + - + + + - - + - + - + + + + - + + + + + + @@ -682,10 +702,18 @@ - + - - + + + + + + + + + + @@ -698,45 +726,165 @@ + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + - + - + + + + + + + + + + + - + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + - - + + @@ -747,9 +895,13 @@ + + + + @@ -760,7 +912,7 @@ - + @@ -770,12 +922,7 @@ - - - - - - + @@ -802,7 +949,9 @@ - + + + @@ -811,15 +960,19 @@ - - + + - + + + + - + + @@ -840,11 +993,11 @@ - + - - + + @@ -868,7 +1021,7 @@ - + @@ -880,7 +1033,7 @@ - + @@ -892,7 +1045,7 @@ - + @@ -920,6 +1073,24 @@ + + + + + + + + + + + + + + + + + + @@ -931,7 +1102,7 @@ - + @@ -942,6 +1113,7 @@ + @@ -950,12 +1122,14 @@ + - + + @@ -988,21 +1162,25 @@ - - - - + + + + - - - - - - - + + + + + + + + + + + @@ -1016,7 +1194,7 @@ - + @@ -1029,11 +1207,11 @@ - + - + @@ -1041,38 +1219,41 @@ - + - - + - + - - - - + + + + - + - + - + + + - - + + + + - + @@ -1135,30 +1316,31 @@ - - - - + + + + + - + - - + + - + - + @@ -1241,7 +1423,7 @@ - + @@ -1253,10 +1435,10 @@ - - + + - + @@ -1269,12 +1451,14 @@ + + - + - + @@ -1289,12 +1473,14 @@ + + - + - + @@ -1386,10 +1572,23 @@ + + + + + + + + + + + + + - + @@ -1397,6 +1596,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1413,10 +1662,10 @@ - - + + - + @@ -1446,14 +1695,17 @@ - + - - + + + + + @@ -1472,9 +1724,9 @@ - + - + @@ -1508,88 +1760,569 @@ + + + + + + - - - - - - + + + + + + + + + + - + - + - + - + - + + + + + + + + - + + + + + + + + + - + - + + + + + + - - - - - + + + + + + - - - - - - - + + + + + + - + + + + + + - - - - + + + + + + - - + + + + + + - - + + + + + + + + - + + + + + - - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1691,33 +2424,30 @@ - + - - + - - + + + - - - - - - - + + + + - + - + @@ -1728,38 +2458,34 @@ - + - + - - + - + - + - + - - - - + @@ -1767,10 +2493,77 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1829,11 +2622,12 @@ - - - - - + + + + + + @@ -1857,7 +2651,6 @@ - @@ -1872,20 +2665,46 @@ - - - + + + - - - - - - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1904,15 +2723,15 @@ - + - - + + - + @@ -1936,8 +2755,8 @@ - - + + @@ -1945,33 +2764,114 @@ - - - - - + + + + + - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + - - - @@ -1993,11 +2893,11 @@ - + - + @@ -2047,10 +2947,12 @@ - - - - + + + + + + @@ -2120,19 +3022,20 @@ - - + + + - + - + - + - + @@ -2140,15 +3043,18 @@ - + - + + + + @@ -2173,6 +3079,8 @@ + + @@ -2182,14 +3090,18 @@ - - + + + + + + @@ -2222,6 +3134,8 @@ + + @@ -2236,28 +3150,33 @@ + + + + + - - - - - - - - - - + + + + + + + + + + @@ -2277,7 +3196,7 @@ - + @@ -2399,6 +3318,8 @@ + + @@ -2449,10 +3370,12 @@ + + - + @@ -2497,6 +3420,8 @@ + + @@ -2552,6 +3477,8 @@ + + @@ -2585,6 +3512,7 @@ + @@ -2600,6 +3528,7 @@ + @@ -2633,6 +3562,7 @@ + @@ -2648,11 +3578,17 @@ + - + + + + + + @@ -2688,6 +3624,7 @@ + @@ -2703,11 +3640,17 @@ + - + + + + + + @@ -2739,6 +3682,7 @@ + @@ -2754,6 +3698,7 @@ + @@ -2783,6 +3728,7 @@ + @@ -2807,6 +3753,7 @@ + @@ -2836,6 +3783,7 @@ + @@ -2860,6 +3808,7 @@ + @@ -2893,6 +3842,7 @@ + @@ -2917,6 +3867,7 @@ + @@ -2946,6 +3897,7 @@ + @@ -2970,6 +3922,7 @@ + @@ -2997,6 +3950,9 @@ + + + @@ -3024,6 +3980,9 @@ + + + @@ -3031,25 +3990,78 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - - + + + - - + + + + + + + + + + + + + + + + + + + + + - + + @@ -3089,6 +4101,7 @@ + @@ -3142,6 +4155,12 @@ + + + + + + @@ -3160,71 +4179,71 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3310,34 +4329,160 @@ + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + @@ -3350,10 +4495,13 @@ - + + + + - + @@ -3366,10 +4514,23 @@ - + + + + + + + + + + + + + + - + @@ -3382,10 +4543,13 @@ - + + + + - + @@ -3399,10 +4563,11 @@ - + + - + @@ -3415,11 +4580,9 @@ - - - + @@ -3433,10 +4596,10 @@ - + - + @@ -3444,31 +4607,31 @@ - - - - - - - - - - + + + + + + + + + + - + - + - + @@ -3486,10 +4649,10 @@ - + - + @@ -3504,10 +4667,10 @@ - + - + @@ -3521,7 +4684,7 @@ - + @@ -3539,10 +4702,10 @@ - + - + @@ -3557,10 +4720,10 @@ - + - + @@ -3574,10 +4737,10 @@ - + - + @@ -3591,7 +4754,7 @@ - + @@ -3608,7 +4771,7 @@ - + @@ -3626,7 +4789,7 @@ - + @@ -3644,7 +4807,7 @@ - + @@ -3662,7 +4825,7 @@ - + @@ -3680,7 +4843,7 @@ - + @@ -3698,7 +4861,7 @@ - + @@ -3715,7 +4878,7 @@ - + @@ -3733,7 +4896,7 @@ - + @@ -3751,7 +4914,7 @@ - + @@ -3768,7 +4931,7 @@ - + @@ -3785,7 +4948,7 @@ - + @@ -3803,7 +4966,7 @@ - + @@ -3823,43 +4986,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + @@ -3867,24 +5032,25 @@ + + - - - + + + - + - - + @@ -3892,11 +5058,11 @@ - - + + - - + + @@ -3917,20 +5083,22 @@ + + - + - + - + - + - - + + @@ -3950,8 +5118,8 @@ - - + + @@ -3961,12 +5129,15 @@ - - + + + - + + + @@ -3974,7 +5145,7 @@ - + @@ -3983,6 +5154,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4092,6 +5358,24 @@ + + + + + + + + + + + + + + + + + + @@ -4161,7 +5445,7 @@ - + @@ -4200,6 +5484,8 @@ + + @@ -4229,6 +5515,8 @@ + + @@ -4251,89 +5539,105 @@ + + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + + + + + + + + + + + + + + + @@ -4343,10 +5647,13 @@ + + + @@ -4356,6 +5663,7 @@ + @@ -4440,13 +5748,16 @@ - - + + + + + @@ -4454,10 +5765,10 @@ - - - - + + + + @@ -4468,16 +5779,17 @@ - - + + + - + - + @@ -4487,6 +5799,7 @@ + @@ -4503,8 +5816,10 @@ + + @@ -4549,11 +5864,11 @@ - - - - - + + + + + @@ -4610,7 +5925,7 @@ - + @@ -4619,7 +5934,7 @@ - + @@ -4680,6 +5995,7 @@ + @@ -4688,12 +6004,13 @@ + - + @@ -4724,7 +6041,7 @@ - + @@ -4742,7 +6059,7 @@ - + @@ -4762,7 +6079,7 @@ - + @@ -4790,7 +6107,7 @@ - + @@ -4806,7 +6123,7 @@ - + @@ -4820,7 +6137,7 @@ - + @@ -4834,7 +6151,7 @@ - + @@ -4856,7 +6173,7 @@ - + @@ -4873,7 +6190,7 @@ - + @@ -4890,7 +6207,7 @@ - + @@ -4921,7 +6238,8 @@ - + + @@ -5002,7 +6320,7 @@ - + @@ -5015,12 +6333,16 @@ + + - - + + - + + + @@ -5028,12 +6350,12 @@ - - - - + + + + - + @@ -5060,16 +6382,16 @@ - - - - + + + + - - - + + + - + @@ -5080,12 +6402,12 @@ - - - - + + + + - + @@ -5096,18 +6418,18 @@ - - - - + + + + - + - + @@ -5122,51 +6444,86 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5176,6 +6533,12 @@ + + + + + + @@ -5195,61 +6558,89 @@ - + + + + - - + + - - + + - - + + + + - - - - + + - - + + - - + + - - + + - - + + - - + + + + - + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + @@ -5260,6 +6651,7 @@ + @@ -5293,67 +6685,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + - + - - - - - - - + - + + + + + + - - - - - - - - - + + - - + + - - - - + + + - + + - + + - + + @@ -5362,8 +6820,9 @@ - + + @@ -5374,6 +6833,7 @@ + @@ -5389,6 +6849,7 @@ + @@ -5399,20 +6860,25 @@ - - - + + + + + + + - - - + + + + - + - + @@ -5454,10 +6920,10 @@ - - + + - + @@ -5471,7 +6937,7 @@ - + @@ -5481,23 +6947,61 @@ - - - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5508,10 +7012,11 @@ + - + @@ -5524,7 +7029,7 @@ - + @@ -5536,9 +7041,7 @@ - - - + @@ -5550,32 +7053,34 @@ + - + - + - + - + + - + - + @@ -5584,7 +7089,7 @@ - + @@ -5593,6 +7098,8 @@ + + @@ -5671,6 +7178,7 @@ + @@ -5681,18 +7189,34 @@ + - + + + + + + + + + + + + + - - - - - - + + + + + + + + + @@ -5731,10 +7255,12 @@ - + + + @@ -5782,6 +7308,21 @@ + + + + + + + + + + + + + + + @@ -5793,17 +7334,34 @@ + + + + + + + + + + + + + + + + + + - @@ -5846,6 +7404,7 @@ + @@ -5866,13 +7425,19 @@ - + + + + + + + @@ -5881,6 +7446,7 @@ + @@ -5895,30 +7461,87 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + - + - + - + - + @@ -5967,6 +7590,7 @@ + @@ -6054,6 +7678,7 @@ + @@ -6065,19 +7690,118 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -6134,6 +7858,9 @@ + + + @@ -6152,6 +7879,7 @@ + @@ -6315,5 +8043,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/index2autolinker.py b/index2autolinker.py index 863ad363e..4b18c89d0 100755 --- a/index2autolinker.py +++ b/index2autolinker.py @@ -18,40 +18,42 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -''' This script produces a definition file for AutoLinker extension - - The definitions are written in JSON in the following format: - - { - "groups" : [ - { - name : "string", - OPTIONAL base_url : "string", END - urls : [ "url", "url", ... ], - }, - ... - ], - "links" : [ - { - string : "string", - EITHER on_group : "name" OR on_page : "url" END - target : "url", - }, - ... - ], - } -''' - import argparse import json -from index_transform.autolinker import * + +from index_transform.autolinker import Index2AutolinkerGroups +from index_transform.autolinker import Index2AutolinkerLinks + def main(): + ''' This script produces a definition file for AutoLinker extension + + The definitions are written in JSON in the following format: + + { + "groups" : [ + { + name : "string", + OPTIONAL base_url : "string", END + urls : [ "url", "url", ... ], + }, + ... + ], + "links" : [ + { + string : "string", + EITHER on_group : "name" OR on_page : "url" END + target : "url", + }, + ... + ], + } + ''' parser = argparse.ArgumentParser(prog='index2autolinker') parser.add_argument('index', type=str, - help='Path to index file to process') + help='Path to index file to process') parser.add_argument('destination', type=str, - help='Path to destination file to store results to') + help='Path to destination file to store results to') args = parser.parse_args() out_f = open(args.destination, 'w', encoding='utf-8') @@ -64,14 +66,16 @@ def main(): tr.transform_file(args.index) links = tr.links - json_groups = [ v for v in groups.values() ] + json_groups = list(groups.values()) json_groups = sorted(json_groups, key=lambda x: x['name']) links = sorted(links, key=lambda x: x['target']) - out_f.write(json.dumps({ 'groups' : json_groups, 'links' : links}, indent=None, + out_f.write(json.dumps({'groups': json_groups, 'links': links}, + indent=None, separators=(',\n', ': '), sort_keys=True)) out_f.close() + if __name__ == '__main__': main() diff --git a/index2browser.py b/index2browser.py index 734c2a017..1f62c88e8 100755 --- a/index2browser.py +++ b/index2browser.py @@ -18,15 +18,17 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from index_transform.browser import * import argparse +from index_transform.browser import Index2Browser + + def main(): parser = argparse.ArgumentParser(prog='index2browser') parser.add_argument('index', type=str, - help='Path to index file to process') + help='Path to index file to process') parser.add_argument('destination', type=str, - help='Path to destination file to store results to') + help='Path to destination file to store results to') args = parser.parse_args() out_f = open(args.destination, 'w', encoding='utf-8') @@ -62,10 +64,6 @@ def main(): ''') + if __name__ == '__main__': main() - - - - - diff --git a/index2ddg.py b/index2ddg.py index 9789e562f..71d15ed87 100755 --- a/index2ddg.py +++ b/index2ddg.py @@ -20,18 +20,18 @@ import argparse import fnmatch -import json import os -import sys import re +import sys import lxml.etree as e -import lxml.html as html +from lxml import html -from index_transform.common import IndexTransform -from xml_utils import xml_escape from build_link_map import build_link_map -from ddg_parse_html import get_declarations, get_short_description, DdgException +from ddg_parse_html import DdgException +from ddg_parse_html import get_declarations +from ddg_parse_html import get_short_description +from index_transform.common import IndexTransform # Entry types # a class or struct @@ -67,45 +67,45 @@ # a member variable that is described in the same page as the containing class ITEM_TYPE_VARIABLE_INLINEMEM = 11 + def get_item_type(el): if (el.tag == 'const' and el.getparent().tag == 'enum' and - el.get('link') == '.'): + el.get('link') == '.'): return ITEM_TYPE_ENUM_CONST if el.tag == 'function': if el.get('link') == '.': return ITEM_TYPE_FUNCTION_INLINEMEM - else: - return ITEM_TYPE_FUNCTION - if el.tag == 'variable': - if el.get('link') == '.': - return ITEM_TYPE_VARIABLE_INLINEMEM - else: - return ITEM_TYPE_VARIABLE + return ITEM_TYPE_FUNCTION + if el.tag == 'variable': + if el.get('link') == '.': + return ITEM_TYPE_VARIABLE_INLINEMEM + return ITEM_TYPE_VARIABLE if el.tag == 'constructor': if el.get('link') == '.': return ITEM_TYPE_CONSTRUCTOR_INLINEMEM - else: - return ITEM_TYPE_CONSTRUCTOR + return ITEM_TYPE_CONSTRUCTOR if el.tag == 'destructor': if el.get('link') == '.': return ITEM_TYPE_DESTRUCTOR_INLINEMEM - else: - return ITEM_TYPE_DESTRUCTOR + return ITEM_TYPE_DESTRUCTOR if el.tag == 'class': return ITEM_TYPE_CLASS if el.tag == 'enum': return ITEM_TYPE_ENUM - return None # not recognized + return None # not recognized + class DDGDebug: - def __init__(self, enabled=False, ident_match=None, debug_abstracts_path=None): + def __init__(self, enabled=False, ident_match=None, + debug_abstracts_path=None): self.enabled = enabled self.ident_match = ident_match self.stat_line_nums = [] self.debug_abstracts_file = sys.stdout if debug_abstracts_path is not None: - self.debug_abstracts_file = open(debug_abstracts_path, 'w', encoding='utf-8') + self.debug_abstracts_file = \ + open(debug_abstracts_path, 'w', encoding='utf-8') # track the statistics of number of lines used by the entries def submit_line_num(self, line_num): @@ -126,11 +126,12 @@ def should_skip_ident(self, ident): return False return True + class Index2DuckDuckGoList(IndexTransform): def __init__(self, ident_map): self.ident_map = ident_map - super(Index2DuckDuckGoList, self).__init__(ignore_typedefs=True) + super().__init__(ignore_typedefs=True) def process_item_hook(self, el, full_name, full_link): @@ -139,16 +140,18 @@ def process_item_hook(self, el, full_name, full_link): if full_link in self.ident_map: self.ident_map[full_link][full_name] = item_type else: - self.ident_map[full_link] = { full_name : item_type } + self.ident_map[full_link] = {full_name: item_type} IndexTransform.process_item_hook(self, el, full_name, full_link) + def get_html_files(root): files = [] - for dir, dirnames, filenames in os.walk(root): + for dir, _, filenames in os.walk(root): for filename in fnmatch.filter(filenames, '*.html'): files.append(os.path.join(dir, filename)) return files + def get_processing_instructions(ident_map, link_map): proc_ins = {} @@ -156,44 +159,48 @@ def get_processing_instructions(ident_map, link_map): if link in link_map.mapping: fn = link_map.mapping[link] if fn not in proc_ins: - proc_ins[fn] = { 'fn': fn, 'link': link, 'idents': {}} + proc_ins[fn] = {'fn': fn, 'link': link, 'idents': {}} for ident in ident_map[link]: - proc_ins[fn]['idents'][ident] = { 'ident' : ident, - 'type' : ident_map[link][ident] } + proc_ins[fn]['idents'][ident] = {'ident': ident, + 'type': ident_map[link][ident]} return proc_ins + # process the files # returns the unqualified name of an identifier def get_unqualified_name(ident): if ident.find('(') != -1: - ident = re.sub('\(.*?\)', '', ident) + ident = re.sub(r'\(.*?\)', '', ident) if ident.find('<') != -1: - ident = re.sub('\<.*?\>', '', ident) + ident = re.sub(r'\<.*?\>', '', ident) qpos = ident.rfind('::') if qpos != -1: ident = ident[qpos+2:] return ident + # returns the version number common to all declarations. Returns none if two # declarations have different version numbers or if no version number is # provided def get_version(decls): rv = None - for code,v in decls: + for code, v in decls: if v: - if rv == None: + if rv is None: rv = v elif v != rv: return None return rv -def build_abstract(decls, desc, max_code_lines, split_code_lines, debug=DDGDebug()): + +def build_abstract(decls, desc, max_code_lines, split_code_lines, + debug=DDGDebug()): limited = False code_snippets = [] - for i,(code,ver) in enumerate(decls): + for i, (code, ver) in enumerate(decls): code = code.strip() code = code.replace('<', '<').replace('>', '>') code_num_lines = code.count('\n') + 1 @@ -201,8 +208,8 @@ def build_abstract(decls, desc, max_code_lines, split_code_lines, debug=DDGDebug # limit the number of code snippets to be included so that total number # of lines is less than max_code_lines. The limit becomes active only # for the second and subsequent snippets. - first = True if i == 0 else False; - last = True if i == len(decls)-1 else False; + first = (i == 0) + last = (i == len(decls)-1) if not first: if last: @@ -220,16 +227,18 @@ def build_abstract(decls, desc, max_code_lines, split_code_lines, debug=DDGDebug max_code_lines -= code_num_lines if split_code_lines: - code_snippets = ['
' + s + '
' for s in code_snippets] + code_snippets = ['
' + s + '
' + for s in code_snippets] code_text = ''.join(code_snippets) else: code_text = '
' + '\n\n'.join(code_snippets) + '
' if limited: - code_text += '\n

Additional declarations have been omitted

' + code_text += \ + '\n

Additional declarations have been omitted

' # count the number of lines used - num_lines = code_text.count('\n') + 1 # last line has no newline after it + num_lines = code_text.count('\n') + 1 # last line has no newline after it if len(desc) > 110: num_lines += 2 else: @@ -252,37 +261,37 @@ def build_abstract(decls, desc, max_code_lines, split_code_lines, debug=DDGDebug print("# END ========") return result_text -''' Outputs additional redirects for an identifier. - - Firstly, we replace '::' with spaces. Then we add two redirects: one with - unchanged text and another with '_' replaced with spaces. We strip one - level of namespace/class qualification and repeat the process with the - remaining text. - - For constructors and destructors, we strip the function name and apply the - abovementioned algorithm, the only difference being that we append - (or prepend) 'constructor' or 'destructor' to the title of the redirect - respectively. - - Each redirect has a 'priority', which is defined by the number of stripped - namespace/class qualifications from the entry that produced the redirect. - This is used to remove duplicate redirects. For each group of duplicate - redirects, we find the redirect with the highest priority (i.e. lowest - number of qualifications stripped) and remove all other redirects. If the - number of highest-priority redirects is more than one, then we remove all - redirects from the group altogether. - - We don't add any redirects to specializations, overloads or operators. -''' -''' array of dict { 'title' -> redirect title, - 'target' -> redirect target, - 'priority' -> redirect priority as int - } -''' def build_redirects(redirects, item_ident, item_type): - - for ch in [ '(', ')', '<', '>', 'operator' ]: + ''' Outputs additional redirects for an identifier. + + Firstly, we replace '::' with spaces. Then we add two redirects: one + with unchanged text and another with '_' replaced with spaces. We strip + one level of namespace/class qualification and repeat the process with + the remaining text. + + For constructors and destructors, we strip the function name and apply + the abovementioned algorithm, the only difference being that we append + (or prepend) 'constructor' or 'destructor' to the title of the redirect + respectively. + + Each redirect has a 'priority', which is defined by the number of + stripped namespace/class qualifications from the entry that produced + the redirect. This is used to remove duplicate redirects. For each + group of duplicate redirects, we find the redirect with the highest + priority (i.e. lowest number of qualifications stripped) and remove all + other redirects. If the number of highest-priority redirects is more + than one, then we remove all redirects from the group altogether. + + We don't add any redirects to specializations, overloads or operators. + ''' + ''' array of dict { 'title' -> redirect title, + 'target' -> redirect target, + 'priority' -> redirect priority as int + } + ''' + + for ch in ['(', ')', '<', '>', 'operator']: if ch in item_ident: return @@ -299,41 +308,43 @@ def do_parts(redirects, parts, prepend='', append=''): p = 0 while p < len(parts): redir1 = prepend + ' '.join(parts[p:]) + append - redir2 = prepend + ' '.join(x.replace('_',' ') for x in parts[p:]) + append + redir2 = prepend + \ + ' '.join(x.replace('_', ' ') for x in parts[p:]) + append redir1 = redir1.replace(' ', ' ').replace(' ', ' ') redir2 = redir2.replace(' ', ' ').replace(' ', ' ') - redirects.append({'title' : redir1, 'target' : target, - 'priority' : p}) + redirects.append({'title': redir1, 'target': target, + 'priority': p}) if redir1 != redir2: - redirects.append({'title' : redir2, 'target' : target, - 'priority' : p}) + redirects.append({'title': redir2, 'target': target, + 'priority': p}) p += 1 # ----- - if item_type in [ ITEM_TYPE_CLASS, - ITEM_TYPE_FUNCTION, - ITEM_TYPE_FUNCTION_INLINEMEM, - ITEM_TYPE_VARIABLE, - ITEM_TYPE_VARIABLE_INLINEMEM, - ITEM_TYPE_ENUM, - ITEM_TYPE_ENUM_CONST ]: + if item_type in [ITEM_TYPE_CLASS, + ITEM_TYPE_FUNCTION, + ITEM_TYPE_FUNCTION_INLINEMEM, + ITEM_TYPE_VARIABLE, + ITEM_TYPE_VARIABLE_INLINEMEM, + ITEM_TYPE_ENUM, + ITEM_TYPE_ENUM_CONST]: do_parts(redirects, parts) - elif item_type in [ ITEM_TYPE_CONSTRUCTOR, - ITEM_TYPE_CONSTRUCTOR_INLINEMEM ]: + elif item_type in [ITEM_TYPE_CONSTRUCTOR, + ITEM_TYPE_CONSTRUCTOR_INLINEMEM]: parts.pop() do_parts(redirects, parts, prepend='constructor') do_parts(redirects, parts, append='constructor') - elif item_type in [ ITEM_TYPE_DESTRUCTOR, - ITEM_TYPE_DESTRUCTOR_INLINEMEM ]: + elif item_type in [ITEM_TYPE_DESTRUCTOR, + ITEM_TYPE_DESTRUCTOR_INLINEMEM]: parts.pop() do_parts(redirects, parts, prepend='destructor') do_parts(redirects, parts, append='destructor') else: pass # should not be here + def output_redirects(out, redirects): # convert to a convenient data structure @@ -353,7 +364,7 @@ def output_redirects(out, redirects): redir_map[title][priority].append(target) # get non-duplicate redirects - ok_redirects = [] # list ( dict { 'title' : title, 'target' : target }) + ok_redirects = [] # list ( dict { 'title' : title, 'target' : target }) for title in redir_map: # priority decreases with increasing values @@ -361,7 +372,7 @@ def output_redirects(out, redirects): if len(redir_map[title][highest_prio]) == 1: # not duplicate target = redir_map[title][highest_prio][0] - ok_redirects.append({ 'title' : title, 'target' : target }) + ok_redirects.append({'title': title, 'target': target}) # sort the redirects ok_redirects = sorted(ok_redirects, key=lambda x: x['title']) @@ -379,50 +390,58 @@ def output_redirects(out, redirects): line += '\t\t\t\t\t\t\t\t\t\t\n' out.write(line) + def process_identifier(out, redirects, root, link, item_ident, item_type, opts, debug=DDGDebug()): # get the name by extracting the unqualified identifier name = get_unqualified_name(item_ident) - debug_verbose = True if debug.enabled and debug.ident_match is not None else False + debug_verbose = False + if debug.enabled and debug.ident_match is not None: + debug_verbose = True try: if item_type == ITEM_TYPE_CLASS: decls = get_declarations(root, name) - desc = get_short_description(root, get_version(decls), opts.max_sentences, opts.max_characters, - opts.max_paren_chars, debug=debug_verbose) + desc = get_short_description(root, get_version(decls), + opts.max_sentences, + opts.max_characters, + opts.max_paren_chars, + debug=debug_verbose) abstract = build_abstract(decls, desc, opts.max_code_lines, opts.split_code_snippets, debug=debug) - elif item_type in [ ITEM_TYPE_FUNCTION, - ITEM_TYPE_CONSTRUCTOR, - ITEM_TYPE_DESTRUCTOR ]: + elif item_type in [ITEM_TYPE_FUNCTION, + ITEM_TYPE_CONSTRUCTOR, + ITEM_TYPE_DESTRUCTOR]: decls = get_declarations(root, name) - desc = get_short_description(root, get_version(decls), opts.max_sentences, opts.max_characters, - opts.max_paren_chars, debug=debug_verbose) + desc = get_short_description(root, get_version(decls), + opts.max_sentences, + opts.max_characters, + opts.max_paren_chars, + debug=debug_verbose) abstract = build_abstract(decls, desc, opts.max_code_lines, opts.split_code_snippets, debug=debug) - elif item_type in [ ITEM_TYPE_FUNCTION_INLINEMEM, - ITEM_TYPE_CONSTRUCTOR_INLINEMEM, - ITEM_TYPE_DESTRUCTOR_INLINEMEM ]: - raise DdgException("INLINEMEM") # not implemented + elif item_type in [ITEM_TYPE_FUNCTION_INLINEMEM, + ITEM_TYPE_CONSTRUCTOR_INLINEMEM, + ITEM_TYPE_DESTRUCTOR_INLINEMEM]: ''' Implementation notes: * the declarations are possibly versioned * declaration is selected from the member table * the member table is found according to the identifier (last part after :: is enough, hopefully) ''' + raise DdgException("INLINEMEM") # not implemented - elif item_type in [ ITEM_TYPE_VARIABLE, - ITEM_TYPE_VARIABLE_INLINEMEM, - ITEM_TYPE_ENUM ]: - raise DdgException("ENUM") # not implemented + elif item_type in [ITEM_TYPE_VARIABLE, + ITEM_TYPE_VARIABLE_INLINEMEM, + ITEM_TYPE_ENUM]: ''' Implementation notes: * the declarations are possibly versioned ''' + raise DdgException("ENUM") # not implemented elif item_type == ITEM_TYPE_ENUM_CONST: - raise DdgException("ENUM_CONST") # not implemented ''' Implementation notes: * the abstract will come from the const -> definition table, which is always put before the first heading. @@ -430,6 +449,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type, to split the content at ';' and ',', then search for the name of the enum. If we find duplicates, signal an error. ''' + raise DdgException("ENUM_CONST") # not implemented if debug.enabled: debug.debug_abstracts_file.write("--------------\n") @@ -444,7 +464,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type, # further_reading, external links, disambiguation, images line += '\t\t\t\t\t\t\t\t\t' # abstract - abstract = abstract.replace('\n','\\n') + abstract = abstract.replace('\n', '\\n') line += abstract + '\t' # source url line += 'http://en.cppreference.com/w/' + link + '\n' @@ -454,41 +474,65 @@ def process_identifier(out, redirects, root, link, item_ident, item_type, except DdgException as err: if debug.enabled: - line = '# error (' + str(err) + "): " + link + ": " + item_ident + "\n" + line = '# error ({0}): {1}: {2}\n'.format(str(err), link, + item_ident) out.write(line) + def main(): parser = argparse.ArgumentParser(prog='index2ddg.py') - parser.add_argument('index', type=str, - help='The path to the XML index containing identifier data') - parser.add_argument('reference', type=str, - help=('The path to the downloaded reference (reference ' - 'directory in the downloaded archive)')) - parser.add_argument('output', type=str, - help='The path to destination output.txt file') - parser.add_argument('--split_code_snippets', action='store_true', default=False, - help='Puts each declaration into a separate code snippet.') - parser.add_argument('--max_code_lines', type=int, default=6, - help='Maximum number of lines of code to show in abstract') - parser.add_argument('--max_sentences', type=int, default=1, - help='Maximum number of sentences to use for the description') - parser.add_argument('--max_characters', type=int, default=200, - help='Maximum number of characters to use for the description') - parser.add_argument('--max_paren_chars', type=int, default=40, - help='Maximum size of parenthesized text in the description. '+ - 'Parenthesized chunks longer than that is removed, unless '+ - 'they are within , or tags') - parser.add_argument('--debug', action='store_true', default=False, - help='Enables debug mode.') - parser.add_argument('--debug_ident', type=str, default=None, - help='Processes only the identifiers that match debug_ident') - parser.add_argument('--debug_abstracts_path', type=str, default=None, - help='Path to print the abstracts before newline stripping occurs') + + parser.add_argument( + 'index', type=str, + help='The path to the XML index containing identifier data') + + parser.add_argument( + 'reference', type=str, + help='The path to the downloaded reference (reference directory in ' + 'the downloaded archive)') + + parser.add_argument( + 'output', type=str, + help='The path to destination output.txt file') + + parser.add_argument( + '--split_code_snippets', action='store_true', default=False, + help='Puts each declaration into a separate code snippet.') + + parser.add_argument( + '--max_code_lines', type=int, default=6, + help='Maximum number of lines of code to show in abstract') + + parser.add_argument( + '--max_sentences', type=int, default=1, + help='Maximum number of sentences to use for the description') + + parser.add_argument( + '--max_characters', type=int, default=200, + help='Maximum number of characters to use for the description') + + parser.add_argument( + '--max_paren_chars', type=int, default=40, + help='Maximum size of parenthesized text in the description. ' + 'Parenthesized chunks longer than that is removed, unless they ' + 'are within , or tags') + + parser.add_argument( + '--debug', action='store_true', default=False, + help='Enables debug mode.') + + parser.add_argument( + '--debug_ident', type=str, default=None, + help='Processes only the identifiers that match debug_ident') + + parser.add_argument( + '--debug_abstracts_path', type=str, default=None, + help='Path to print the abstracts before newline stripping occurs') args = parser.parse_args() - # If a the second argument is 'debug', the program switches to debug mode and - # prints everything to stdout. If the third argument is provided, the program - # processes only the identifiers that match the provided string + # If a the second argument is 'debug', the program switches to debug mode + # and prints everything to stdout. If the third argument is provided, the + # program processes only the identifiers that match the provided string debug = DDGDebug(args.debug, args.debug_ident, args.debug_abstracts_path) @@ -504,9 +548,6 @@ def main(): tr = Index2DuckDuckGoList(ident_map) tr.transform_file(index_file) - # get a list of existing pages - html_files = get_html_files(args.reference) - # get a mapping between titles and pages # linkmap = dict { title -> filename } link_map = build_link_map(args.reference) @@ -515,12 +556,12 @@ def main(): proc_ins = get_processing_instructions(ident_map, link_map) # sort proc_ins to produce ordered output.txt - proc_ins = [ v for v in proc_ins.values() ] + proc_ins = list(proc_ins.values()) proc_ins = sorted(proc_ins, key=lambda x: x['link']) for page in proc_ins: idents = page['idents'] - idents = [ v for v in idents.values() ] + idents = list(idents.values()) idents = sorted(idents, key=lambda x: x['ident']) page['idents'] = idents @@ -528,35 +569,37 @@ def main(): out = open(output_file, 'w', encoding='utf-8') - #i=1 + # i=1 for page in proc_ins: idents = page['idents'] link = page['link'] fn = page['fn'] - if debug.should_skip_ident([ i['ident'] for i in idents ]): + if debug.should_skip_ident([i['ident'] for i in idents]): continue - #print(str(i) + '/' + str(len(proc_ins)) + ': ' + link) - #i+=1 + # print(str(i) + '/' + str(len(proc_ins)) + ': ' + link) + # i+=1 - root = e.parse(os.path.join(args.reference, fn), parser=html.HTMLParser()) + root = e.parse(os.path.join(args.reference, fn), + parser=html.HTMLParser()) for ident in idents: item_ident = ident['ident'] item_type = ident['type'] - process_identifier(out, redirects, root, link, item_ident, item_type, - args, debug=debug) + process_identifier(out, redirects, root, link, item_ident, + item_type, args, debug=debug) output_redirects(out, redirects) if debug.enabled: print('=============================') print('Numbers of lines used:') - for i,l in enumerate(debug.stat_line_nums): + for i, l in enumerate(debug.stat_line_nums): print(str(i) + ': ' + str(l) + ' result(s)') + if __name__ == "__main__": main() diff --git a/index2devhelp.py b/index2devhelp.py index ea4f4ca56..e6332d477 100755 --- a/index2devhelp.py +++ b/index2devhelp.py @@ -18,34 +18,36 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from index_transform.devhelp import * import argparse -from xml_utils import xml_escape -import io + +from index_transform.devhelp import transform_devhelp + def main(): parser = argparse.ArgumentParser(prog='index2devhelp') parser.add_argument('book_base', type=str, - help='url to the location of the book') + help='url to the location of the book') parser.add_argument('chapters_path', type=str, - help='path to the chapters file to include') + help='path to the chapters file to include') parser.add_argument('book_title', type=str, - help='the title of the book') + help='the title of the book') parser.add_argument('book_name', type=str, - help='the name of the package') + help='the name of the package') parser.add_argument('rel_link', type=str, - help='the link relative to the root of the documentation') + help='the link relative to the root of the ' + 'documentation') parser.add_argument('in_fn', type=str, - help='the path of the source file') + help='the path of the source file') parser.add_argument('dest_fn', type=str, - help='the path of the destination file') + help='the path of the destination file') args = parser.parse_args() with open(args.dest_fn, 'wb') as out_f: output = transform_devhelp(args.book_title, args.book_name, - args.book_base, args.rel_link, - args.chapters_path, args.in_fn) + args.book_base, args.rel_link, + args.chapters_path, args.in_fn) out_f.write(output) + if __name__ == '__main__': main() diff --git a/index2doxygen-tag.py b/index2doxygen-tag.py index adecfaaf1..f90b89cc1 100755 --- a/index2doxygen-tag.py +++ b/index2doxygen-tag.py @@ -18,22 +18,35 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from index_transform.doxygen_tag import * import argparse -from link_map import LinkMap + from lxml import etree +from index_transform.doxygen_tag import Index2DoxygenTag +from index_transform.doxygen_tag import Item +from index_transform.doxygen_tag import print_map +from link_map import LinkMap + + def main(): parser = argparse.ArgumentParser(prog='index2doxygen-tag') - parser.add_argument('link_map_fn', type=str, - help='Path to index file to process') - parser.add_argument('in_fn', type=str, - help='the file name of the link map or \'web\' if no link remap ' + - 'should be done') - parser.add_argument('chapters_fn', type=str, - help='the file name of the source file') - parser.add_argument('dest_fn', type=str, - help='the file name of the destination file') + parser.add_argument( + 'link_map_fn', type=str, + help='Path to index file to process') + + parser.add_argument( + 'in_fn', type=str, + help='the file name of the link map or \'web\' if no link remap ' + 'should be done') + + parser.add_argument( + 'chapters_fn', type=str, + help='the file name of the source file') + + parser.add_argument( + 'dest_fn', type=str, + help='the file name of the destination file') + args = parser.parse_args() link_map_fn = args.link_map_fn @@ -41,8 +54,6 @@ def main(): chapters_fn = args.chapters_fn dest_fn = args.dest_fn - indent_level_inc = 2 - out_f = open(dest_fn, 'w', encoding='utf-8') link_map = None @@ -57,10 +68,13 @@ def main(): with open(chapters_fn, encoding='utf-8') as chapters_f: chapters_tree = etree.parse(chapters_f) - for header_chapter in chapters_tree.getroot().findall(".//*[@name='Headers']/*"): + for header_chapter in \ + chapters_tree.getroot().findall(".//*[@name='Headers']/*"): out_f.write(' \n') - out_f.write(' %s\n' % header_chapter.attrib['name']) - out_f.write(' %s\n' % header_chapter.attrib['link']) + out_f.write(' {0}\n'.format( + header_chapter.attrib['name'])) + out_f.write(' {0}\n'.format( + header_chapter.attrib['link'])) out_f.write(' std\n') out_f.write(' \n') @@ -70,5 +84,6 @@ def main(): out_f.write(''' ''') + if __name__ == '__main__': main() diff --git a/index2highlight.py b/index2highlight.py index 1d3be6557..d8d80558d 100755 --- a/index2highlight.py +++ b/index2highlight.py @@ -18,15 +18,20 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from index_transform.highlight import * import argparse +from index_transform.highlight import Index2Highlight + + def main(): parser = argparse.ArgumentParser(prog='index2highlight') - parser.add_argument('index', type=str, - help='Path to index file to process') - parser.add_argument('destination', type=str, - help='Path to destination file to store results to') + parser.add_argument( + 'index', type=str, + help='Path to index file to process') + + parser.add_argument( + 'destination', type=str, + help='Path to destination file to store results to') args = parser.parse_args() out_f = open(args.destination, 'w', encoding='utf-8') @@ -34,5 +39,6 @@ def main(): tr = Index2Highlight(out_f) tr.transform_file(args.index) + if __name__ == '__main__': main() diff --git a/index2search.py b/index2search.py index ec75c2abd..ebfcb536c 100755 --- a/index2search.py +++ b/index2search.py @@ -18,15 +18,20 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from index_transform.search import * import argparse +from index_transform.search import Index2Search + + def main(): parser = argparse.ArgumentParser(prog='index2highlight') - parser.add_argument('index', type=str, - help='Path to index file to process') - parser.add_argument('destination', type=str, - help='Path to destination file to store results to') + parser.add_argument( + 'index', type=str, + help='Path to index file to process') + + parser.add_argument( + 'destination', type=str, + help='Path to destination file to store results to') args = parser.parse_args() out_f = open(args.destination, 'w', encoding='utf-8') @@ -34,5 +39,6 @@ def main(): tr = Index2Search(out_f) tr.transform_file(args.index) + if __name__ == '__main__': main() diff --git a/index_transform/autolinker.py b/index_transform/autolinker.py index 6f9a07a75..350d73534 100644 --- a/index_transform/autolinker.py +++ b/index_transform/autolinker.py @@ -20,10 +20,12 @@ from index_transform.common import IndexTransform + def get_rel_name(full_name): pos = full_name.rfind("::") return full_name[pos+2:] + def is_group(el): curr_el = el while True: @@ -33,18 +35,16 @@ def is_group(el): if curr_el.tag == 'index': return True + def needs_entry_in_group(el): - if el.tag == 'const': return True - if el.tag == 'function': return True - if el.tag == 'class': return True - if el.tag == 'enum': return True - if el.tag == 'variable': return True - return False + tags = ['const', 'function', 'class', 'enum', 'variable'] + return el.tag in tags + class Index2AutolinkerGroups(IndexTransform): def __init__(self): - super(Index2AutolinkerGroups, self).__init__(ignore_typedefs = True) + super().__init__(ignore_typedefs=True) self.groups = {} self.curr_group = None @@ -53,9 +53,9 @@ def process_item_hook(self, el, full_name, full_link): saved_group = self.curr_group self.groups[full_name] = { - 'name' : full_name, - 'base_url' : full_link, - 'urls' : [''] + 'name': full_name, + 'base_url': full_link, + 'urls': [''] } self.curr_group = full_name IndexTransform.process_item_hook(self, el, full_name, full_link) @@ -67,19 +67,20 @@ def process_item_hook(self, el, full_name, full_link): base_url = self.groups[self.curr_group]['base_url'] if full_link.find(base_url) == 0: rel_link = full_link[len(base_url):] - if not rel_link in self.groups[self.curr_group]['urls']: + if rel_link not in self.groups[self.curr_group]['urls']: self.groups[self.curr_group]['urls'].append(rel_link) # else: an error has occurred somewhere - ignore + class Index2AutolinkerLinks(IndexTransform): def __init__(self): - super(Index2AutolinkerLinks, self).__init__() + super().__init__() self.links = [] self.curr_group = None def process_item_hook(self, el, full_name, full_link): - self.links.append({ 'string' : full_name, 'target' : full_link }) + self.links.append({'string': full_name, 'target': full_link}) if is_group(el): saved_group = self.curr_group @@ -89,9 +90,11 @@ def process_item_hook(self, el, full_name, full_link): else: IndexTransform.process_item_hook(self, el, full_name, full_link) - if is_group(el.getparent()) and self.curr_group and needs_entry_in_group(el): + if is_group(el.getparent()) and self.curr_group and \ + needs_entry_in_group(el): - self.links.append({ 'string' : get_rel_name(full_name), - 'target' : full_link, - 'on_group' : self.curr_group - }) + self.links.append({ + 'string': get_rel_name(full_name), + 'target': full_link, + 'on_group': self.curr_group + }) diff --git a/index_transform/browser.py b/index_transform/browser.py index d2e625cb1..fb8b976c0 100644 --- a/index_transform/browser.py +++ b/index_transform/browser.py @@ -21,6 +21,7 @@ from index_transform.common import IndexTransform from xml_utils import xml_escape + class Index2Browser(IndexTransform): def __init__(self, out_file): @@ -28,25 +29,35 @@ def __init__(self, out_file): self.out_file = out_file def output_item(self, el, full_name, full_link): + tag_to_mark = { + 'const': '(const)', + 'function': '(function)', + 'constructor': '(function)', + 'destructor': '(function)', + 'class': '(class)', + 'enum': '(enum)', + 'variable': '(variable)', + 'typedef': '(typedef)', + 'specialization': '(class)', + 'overload': '(function)', + } mark = '' - if el.tag == 'const': mark = '(const)' - elif el.tag == 'function': mark = '(function)' - elif el.tag == 'constructor': mark = '(function)' - elif el.tag == 'destructor': mark = '(function)' - elif el.tag == 'class': mark = '(class)' - elif el.tag == 'enum': mark = '(enum)' - elif el.tag == 'variable': mark = '(variable)' - elif el.tag == 'typedef': mark = '(typedef)' - elif el.tag == 'specialization': mark = '(class)' - elif el.tag == 'overload': mark = '(function)' + if el.tag in tag_to_mark: + mark = tag_to_mark[el.tag] res = u'' - res += '' + xml_escape(full_name) + ' [' - res += '' - res += full_link + '] ' + mark + '\n' + res += '{0} ['.format( + xml_escape(full_name)) + res += ''.format( + xml_escape(full_link)) + res += '{0}] {1}\n'.format( + full_link, mark) + return res def process_item_hook(self, el, full_name, full_link): - self.out_file.write('
  • ' + self.output_item(el, full_name, full_link) + '
      ') + self.out_file.write('
    • ' + + self.output_item(el, full_name, full_link) + + '
        ') IndexTransform.process_item_hook(self, el, full_name, full_link) self.out_file.write('
    • \n') diff --git a/index_transform/common.py b/index_transform/common.py index 127434c36..08e378f61 100755 --- a/index_transform/common.py +++ b/index_transform/common.py @@ -18,6 +18,8 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' +import lxml.etree as e + ''' This is a python script for various transformations of the index. @@ -30,8 +32,6 @@ children. By default just processes the children. ''' -import lxml.etree as e -import re class IndexTransform: @@ -49,18 +49,18 @@ def get_attr(self, el, attr): nm_str = '( name: ' + nm + ' )' else: nm_str = '' - raise Exception('Element \'' + el.tag + '\' does not have attribute \'' + - attr + '\' ' + nm_str) + msg = 'Element \'{0}\' does not have attribute \'{1}\' {2}'.format( + el.tag, attr, nm_str) + raise Exception(msg) return str(a) - """ Returns the relative link of 'el' to its parent, if any - """ - def get_link(self, el, default = None): + # Returns the relative link of 'el' to its parent, if any + def get_link(self, el, default=None): if not default: default = self.get_name(el) link = el.get('link') - if link == None: + if link is None: return default if link == '.': return '' @@ -81,19 +81,19 @@ def get_full_link(self, el, parent_link): alias_name = el.get('alias') if alias_name: return self.get_link(self.get_alias(el, alias_name)) - else: - return self.link_append(el, self.get_link(el), parent_link) + return self.link_append(el, self.get_link(el), parent_link) - elif el.tag == 'constructor': + if el.tag == 'constructor': d_link = parent_link.split('/')[-1] - return self.link_append(el, self.get_link(el, default=d_link), parent_link) + return self.link_append(el, self.get_link(el, default=d_link), + parent_link) - elif el.tag == 'destructor': + if el.tag == 'destructor': d_link = '~' + parent_link.split('/')[-1] - return self.link_append(el, self.get_link(el, default=d_link), parent_link) + return self.link_append(el, self.get_link(el, default=d_link), + parent_link) - else: - return self.link_append(el, self.get_link(el), parent_link) + return self.link_append(el, self.get_link(el), parent_link) """ Returns the name of el """ def get_name(self, el): @@ -109,23 +109,23 @@ def get_full_name(self, el, parent_name): return parent_name + '::' + parent_name.split('::')[-1] if el.tag == 'destructor': return parent_name + '::~' + parent_name.split('::')[-1] - elif el.tag == 'specialization': + if el.tag == 'specialization': return self.get_name(el) + '<' + parent_name + '>' - elif el.tag == 'overload': + if el.tag == 'overload': return self.get_name(el) + '(' + parent_name + ')' - else: - name = '' - if parent_name: - name += parent_name + '::' - name += self.get_name(el) - return name + + name = '' + if parent_name: + name += parent_name + '::' + name += self.get_name(el) + return name """ Returns the element within the document that has a name that matches 'name' """ def get_alias(self, el, name): aliases = el.xpath('/index/class[@name = \'' + name + '\'] |' + - '/index/enum[@name = \'' + name + '\']') + '/index/enum[@name = \'' + name + '\']') if len(aliases) == 0: raise Exception('No aliases found for \'' + name + '\'') if len(aliases) > 1: @@ -134,15 +134,18 @@ def get_alias(self, el, name): """ Processes one item """ def process_item(self, el, parent_name, parent_link): - if el.tag in ['const','function','class','enum','variable','typedef', - 'constructor','destructor','specialization','overload']: + if el.tag in ['const', 'function', 'class', 'enum', 'variable', + 'typedef', 'constructor', 'destructor', 'specialization', + 'overload']: full_name = self.get_full_name(el, parent_name) full_link = self.get_full_link(el, parent_link) self.process_item_hook(el, full_name, full_link) - elif el.tag == 'inherits' and el.getparent().xpath('child::inherits')[0] == el: + elif el.tag == 'inherits' and \ + el.getparent().xpath('child::inherits')[0] == el: + if self.ignore_inherits: return pending = el.getparent().xpath('child::inherits') @@ -179,19 +182,23 @@ def inherits_worker(self, parent_name, pending, finished): # find the source class/enum source = self.get_alias(current, self.get_attr(current, 'name')) - if not source in finished: + if source not in finished: finished.append(source) parent_link = self.get_attr(source, 'link') for source_ch in source: - ignore_tags = ['constructor', 'destructor', 'inherits', 'specialization', 'overload'] - if source_ch.tag in ignore_tags: pass - elif source_ch.tag == 'function' and source_ch.get('name') == 'operator=': pass + ignore_tags = ['constructor', 'destructor', 'inherits', + 'specialization', 'overload'] + if source_ch.tag in ignore_tags: + pass + elif source_ch.tag == 'function' and \ + source_ch.get('name') == 'operator=': + pass else: self.process_item(source_ch, parent_name, parent_link) # append new elements more_pending = source.xpath('child::inherits') - more_pending = [p for p in more_pending if not p is current] + more_pending = [p for p in more_pending if p is not current] pending.extend(more_pending) self.inherits_worker(parent_name, pending, finished) diff --git a/index_transform/devhelp.py b/index_transform/devhelp.py index 61d7b878f..d20e8c183 100644 --- a/index_transform/devhelp.py +++ b/index_transform/devhelp.py @@ -18,11 +18,10 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from index_transform.common import IndexTransform -from xml_utils import xml_escape -from index_transform import * from lxml import etree -import io + +from index_transform.common import IndexTransform + class Index2Devhelp(IndexTransform): @@ -31,17 +30,23 @@ def __init__(self, functions_el): self.functions_el = functions_el def get_mark(self, el): - if el.tag == 'const': return 'macro' - elif el.tag == 'function': return 'function' - elif el.tag == 'constructor': return 'function' - elif el.tag == 'destructor': return 'function' - elif el.tag == 'class': return 'class' - elif el.tag == 'enum': return 'enum' - elif el.tag == 'typedef': return 'typedef' - elif el.tag == 'specialization': return 'class' - elif el.tag == 'overload': return 'function' - # devhelp does not support variables in its format - elif el.tag == 'variable': return '' + tag_to_mark = { + 'const': 'macro', + 'function': 'function', + 'constructor': 'function', + 'destructor': 'function', + 'class': 'class', + 'enum': 'enum', + 'typedef': 'typedef', + 'specialization': 'class', + 'overload': 'function', + # devhelp does not support variables in its format + 'variable': '' + } + + if el.tag in tag_to_mark: + return tag_to_mark[el.tag] + return '' def process_item_hook(self, el, full_name, full_link): @@ -52,8 +57,9 @@ def process_item_hook(self, el, full_name, full_link): IndexTransform.process_item_hook(self, el, full_name, full_link) + def transform_devhelp(book_title, book_name, book_base, rel_link, chapters_fn, - in_fn): + in_fn): root_el = etree.Element('book') root_el.set('xmlns', 'http://www.devhelp.net/book') root_el.set('title', book_title) diff --git a/index_transform/devhelp_qch.py b/index_transform/devhelp_qch.py index 2aa654702..76653721c 100644 --- a/index_transform/devhelp_qch.py +++ b/index_transform/devhelp_qch.py @@ -20,6 +20,7 @@ from lxml import etree + def convert_toc_lines(source_line, in_section): for el_sub in source_line.getchildren(): el_section_1 = etree.SubElement(in_section, 'section') @@ -31,6 +32,7 @@ def convert_toc_lines(source_line, in_section): return in_section + def convert_toc(in_root): el_toc = etree.Element('toc') el_section = etree.SubElement(el_toc, 'section') @@ -44,6 +46,7 @@ def convert_toc(in_root): convert_toc_lines(chapters_el, el_section) return el_toc + def convert_keywords(in_root_k): el_keywords = etree.Element('keywords') @@ -75,6 +78,7 @@ def convert_keywords(in_root_k): return el_keywords + # Adds files list from external library def add_files_list(files_root_f): el_files = etree.Element('files') @@ -83,6 +87,7 @@ def add_files_list(files_root_f): el_file.text = file_item.text return el_files + def convert_devhelp_to_qch(in_root, files_root, virtual_folder): out_root = etree.Element('QtHelpProject') out_root.set('version', "1.0") diff --git a/index_transform/doxygen_tag.py b/index_transform/doxygen_tag.py index 0a5a237a7..73ade7be6 100644 --- a/index_transform/doxygen_tag.py +++ b/index_transform/doxygen_tag.py @@ -18,17 +18,20 @@ along with this program. If not, see http://www.gnu.org/licenses/. ''' -from index_transform.common import IndexTransform from functools import total_ordering + +from index_transform.common import IndexTransform from xml_utils import xml_escape + class ItemKind: - VARIABLE = 0, - FUNCTION = 1, - CLASS = 2, - TYPEDEF = 3, + VARIABLE = 0 + FUNCTION = 1 + CLASS = 2 + TYPEDEF = 3 NAMESPACE = 4 + @total_ordering class Item: @@ -45,17 +48,18 @@ def __eq__(self, other): def __lt__(self, other): return self.full_name < other.full_name + def add_to_map(ns_map, full_name, full_link, item_kind): names = full_name.split('::') parsed_names = [] - last_name = names.pop() # i.e. unqualified name + last_name = names.pop() # i.e. unqualified name curr_item = ns_map for name in names: parsed_names.append(name) if name in curr_item.members: curr_item = curr_item.members[name] - if curr_item.kind not in [ ItemKind.CLASS, ItemKind.NAMESPACE ]: + if curr_item.kind not in [ItemKind.CLASS, ItemKind.NAMESPACE]: print("ERROR: " + name + " in " + full_name + " is not a class or namespace") return @@ -73,8 +77,10 @@ def add_to_map(ns_map, full_name, full_link, item_kind): if last_name in curr_item.members: curr_item = curr_item.members[last_name] if (item_kind == ItemKind.CLASS and - curr_item.kind in [ ItemKind.CLASS, ItemKind.NAMESPACE ]): - curr_item.kind = item_kind # fix namespaces that are actually classes + curr_item.kind in [ItemKind.CLASS, ItemKind.NAMESPACE]): + + # fix namespaces that are actually classes + curr_item.kind = item_kind curr_item.link = full_link else: print("ERROR: Duplicate element: " + full_name) @@ -88,81 +94,97 @@ def add_to_map(ns_map, full_name, full_link, item_kind): curr_item = new_item return + def print_members(out_f, link_map, curr_item): for item in sorted(curr_item.members.values()): if link_map: link = link_map.get_dest(item.link) - if link == None and item.kind != ItemKind.NAMESPACE: + if link is None and item.kind != ItemKind.NAMESPACE: print("WARN: " + item.full_name + " contains invalid link") link = '404' else: link = item.link if item.kind == ItemKind.VARIABLE: - out_f.write(' \n' + - ' T\n' + - ' ' + xml_escape(item.name) + '\n' + - ' ' + xml_escape(link) + '\n' + - ' \n' + - ' \n' + - ' \n') + out_f.write( + ' \n' + + ' T\n' + + ' ' + xml_escape(item.name) + '\n' + + ' ' + xml_escape(link) + '\n' + + ' \n' + + ' \n' + + ' \n') elif item.kind == ItemKind.FUNCTION: - out_f.write(' \n' + - ' T\n' + - ' ' + xml_escape(item.name) + '\n' + - ' ' + xml_escape(link) + '\n' + - ' \n' + - ' (T... args)\n' + - ' \n') + out_f.write( + ' \n' + + ' T\n' + + ' ' + xml_escape(item.name) + '\n' + + ' ' + xml_escape(link) + '\n' + + ' \n' + + ' (T... args)\n' + + ' \n') elif item.kind == ItemKind.CLASS: - out_f.write(' ' + xml_escape(item.full_name) + '\n') + out_f.write( + ' ' + xml_escape(item.full_name) + + '\n') elif item.kind == ItemKind.NAMESPACE: - out_f.write(' ' + xml_escape(item.full_name) + '\n') + out_f.write( + ' ' + xml_escape(item.full_name) + + '\n') + def print_map_item(out_f, link_map, curr_item): - item_kind_to_attr = { ItemKind.NAMESPACE : 'namespace', - ItemKind.CLASS : 'class' } + item_kind_to_attr = {ItemKind.NAMESPACE: 'namespace', + ItemKind.CLASS: 'class'} if curr_item.kind not in item_kind_to_attr: print('ERROR: only namespaces and classes can have members') return - out_f.write(' \n' + - ' ' + xml_escape(curr_item.full_name) + '\n' + - ' ' + xml_escape(curr_item.link) + '\n') + out_f.write( + ' \n' + + ' ' + xml_escape(curr_item.full_name) + '\n' + + ' ' + xml_escape(curr_item.link) + '\n') print_members(out_f, link_map, curr_item) out_f.write(' \n') for item in sorted(curr_item.members.values()): - if item.kind in [ ItemKind.NAMESPACE, ItemKind.CLASS ]: + if item.kind in [ItemKind.NAMESPACE, ItemKind.CLASS]: print_map_item(out_f, link_map, item) + def print_map(out_f, link_map, ns_map): for item in sorted(ns_map.members.values()): - if item.kind in [ ItemKind.NAMESPACE, ItemKind.CLASS ]: + if item.kind in [ItemKind.NAMESPACE, ItemKind.CLASS]: print_map_item(out_f, link_map, item) else: print("WARN: " + item.full_name + " ignored") + class Index2DoxygenTag(IndexTransform): def __init__(self, ns_map): super().__init__() self.ns_map = ns_map def get_item_kind(self, el): - if el.tag == 'const': return None - elif el.tag == 'function': return ItemKind.FUNCTION - elif el.tag == 'constructor': return ItemKind.FUNCTION - elif el.tag == 'destructor': return ItemKind.FUNCTION - elif el.tag == 'class': return ItemKind.CLASS - elif el.tag == 'enum': return 'enum' - elif el.tag == 'typedef': return ItemKind.CLASS - elif el.tag == 'specialization': return None - elif el.tag == 'overload': return None - elif el.tag == 'variable': return ItemKind.VARIABLE + tag_to_kind = { + 'const': None, + 'function': ItemKind.FUNCTION, + 'constructor': ItemKind.FUNCTION, + 'destructor': ItemKind.FUNCTION, + 'class': ItemKind.CLASS, + 'enum': 'enum', + 'typedef': ItemKind.CLASS, + 'specialization': None, + 'overload': None, + 'variable': ItemKind.VARIABLE, + } + + if el.tag in tag_to_kind: + return tag_to_kind[el.tag] return None def process_item_hook(self, el, full_name, full_link): item_kind = self.get_item_kind(el) - if item_kind != None: + if item_kind is not None: add_to_map(self.ns_map, full_name, full_link, item_kind) IndexTransform.process_item_hook(self, el, full_name, full_link) diff --git a/index_transform/highlight.py b/index_transform/highlight.py index 5c8176b6f..289f8e6ce 100644 --- a/index_transform/highlight.py +++ b/index_transform/highlight.py @@ -20,6 +20,7 @@ from index_transform.common import IndexTransform + class Index2Highlight(IndexTransform): def __init__(self, out_file): super().__init__() @@ -28,23 +29,31 @@ def __init__(self, out_file): def check_is_member(self, el): if el.getparent().tag == 'index': return False - if el.tag == 'function': return True - elif el.tag == 'variable': return True - elif el.tag == 'constructor': return True - elif el.tag == 'destructor': return True + if el.tag == 'function': + return True + if el.tag == 'variable': + return True + if el.tag == 'constructor': + return True + if el.tag == 'destructor': + return True return False def process_item_hook(self, el, full_name, full_link): - is_member = False - if self.check_is_member(el): pass - elif '<' in full_name: pass - elif '>' in full_name: pass - elif '(' in full_name: pass - elif ')' in full_name: pass + if self.check_is_member(el): + pass + elif '<' in full_name: + pass + elif '>' in full_name: + pass + elif '(' in full_name: + pass + elif ')' in full_name: + pass else: self.out_file.write(full_name + ' => ' + full_link + '\n') IndexTransform.process_item_hook(self, el, full_name, full_link) def inherits_worker(self, parent_name, pending, finished=list()): - pass # do not walk the inheritance hierarchy + pass # do not walk the inheritance hierarchy diff --git a/index_transform/search.py b/index_transform/search.py index 9be63fc33..a629c2ca6 100644 --- a/index_transform/search.py +++ b/index_transform/search.py @@ -20,6 +20,7 @@ from index_transform.common import IndexTransform + class Index2Search(IndexTransform): def __init__(self, out_file): super().__init__() @@ -29,4 +30,3 @@ def process_item_hook(self, el, full_name, full_link): self.out_file.write(full_name + ' => ' + full_link + '\n') IndexTransform.process_item_hook(self, el, full_name, full_link) - diff --git a/link_map.py b/link_map.py index 156ffbafb..64f2631aa 100644 --- a/link_map.py +++ b/link_map.py @@ -20,6 +20,7 @@ import lxml.etree as e + class LinkMap: def __init__(self): self.mapping = dict() diff --git a/misc/fontforge-gen.python b/misc/fontforge-gen.python index c042eecc0..ec8982f17 100644 --- a/misc/fontforge-gen.python +++ b/misc/fontforge-gen.python @@ -18,11 +18,12 @@ # along with this program. If not, see http://www.gnu.org/licenses/. -import fontforge import os -import psMat import sys +import fontforge +import psMat + inputFont = sys.argv[1] outputFont = os.path.splitext(inputFont)[0] + "Condensed80.otf" diff --git a/preprocess-css.css b/preprocess-css.css index 53547f25a..2e20f40e5 100644 --- a/preprocess-css.css +++ b/preprocess-css.css @@ -14,7 +14,7 @@ div#content { } html, body { - font-family: "DejaVu Sans", arial, sans-serif; + font-family: DejaVuSans, "DejaVu Sans", arial, sans-serif; font-size: 1em; } @@ -31,21 +31,21 @@ pre, } .t-dcl-list-see-monospace > span { - font-family: "DejaVu Sans Mono", courier, monospace; + font-family: DejaVuSansMono, "DejaVu Sans Mono", courier, monospace; } .t-sb-list-ln-table tr > td:first-child { - font-family: "DejaVu Sans Mono", courier, monospace; + font-family: DejaVuSansMono, "DejaVu Sans Mono", courier, monospace; } .t-param-list-item > td:first-child { - font-family: "DejaVu Sans Mono", courier, monospace; + font-family: DejaVuSansMono, "DejaVu Sans Mono", courier, monospace; } .t-dcl-member-div > div:first-child { - font-family: "DejaVu Sans Mono", courier, monospace; + font-family: DejaVuSansMono, "DejaVu Sans Mono", courier, monospace; } .t-dcl-member-nobold-div > div:first-child { - font-family: "DejaVu Sans", arial, sans-serif; + font-family: DejaVuSans, "DejaVu Sans", arial, sans-serif; } diff --git a/preprocess.py b/preprocess.py index 3fe09e0e4..65e73d61f 100755 --- a/preprocess.py +++ b/preprocess.py @@ -17,16 +17,23 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. -from commands import preprocess import argparse import concurrent.futures import os import shutil +from commands import preprocess + + def main(): parser = argparse.ArgumentParser(prog='preprocess.py') - parser.add_argument('--src', type=str, help='Source directory where raw website copy resides') - parser.add_argument('--dst', type=str, help='Destination folder to put preprocessed archive to') + parser.add_argument( + '--src', type=str, + help='Source directory where raw website copy resides') + + parser.add_argument( + '--dst', type=str, + help='Destination folder to put preprocessed archive to') args = parser.parse_args() root = args.dst @@ -38,25 +45,24 @@ def main(): preprocess.rearrange_archive(root) - rename_map = preprocess.find_files_to_be_renamed(root) - preprocess.rename_files(rename_map) + rename_map = preprocess.build_rename_map(root) + preprocess.rename_files(root, rename_map) # clean the html files file_list = preprocess.find_html_files(root) with concurrent.futures.ProcessPoolExecutor() as executor: - futures = [executor.submit(preprocess.preprocess_html_file, root, fn, - rename_map) - for fn in enumerate(file_list)] + futures = [ + executor.submit(preprocess.preprocess_html_file, + root, fn, rename_map) + for fn in file_list + ] for future in futures: output = future.result() if len(output) > 0: print(output) - for fn in preprocess.find_html_files(root): - preprocess.preprocess_html_file(root, fn, rename_map) - # append css modifications with open(os.path.join(root, 'common/site_modules.css'), "a") as out: with open("preprocess-css.css", "r") as pp: @@ -64,9 +70,13 @@ def main(): # clean the css files - for fn in [ os.path.join(root, 'common/site_modules.css'), - os.path.join(root, 'common/ext.css') ]: + for fn in [os.path.join(root, 'common/site_modules.css'), + os.path.join(root, 'common/ext.css')]: preprocess.preprocess_css_file(fn) + preprocess.preprocess_startup_script( + os.path.join(root, 'common/startup_scripts.js')) + + if __name__ == "__main__": main() diff --git a/preprocess_qch.py b/preprocess_qch.py index 606c330f3..856afb57c 100755 --- a/preprocess_qch.py +++ b/preprocess_qch.py @@ -17,20 +17,27 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. -from commands import preprocess_cssless import argparse import concurrent.futures import os import shutil +from commands import preprocess_cssless + + def main(): parser = argparse.ArgumentParser(prog='preprocess_qch.py') - parser.add_argument('--src', required=True, type=str, - help='Source directory where raw website copy resides') - parser.add_argument('--dst', required=True, type=str, - help='Destination folder to put preprocessed archive to') - parser.add_argument('--verbose', action='store_true', default=False, - help='If set, verbose output is produced') + parser.add_argument( + '--src', required=True, type=str, + help='Source directory where raw website copy resides') + + parser.add_argument( + '--dst', required=True, type=str, + help='Destination folder to put preprocessed archive to') + + parser.add_argument( + '--verbose', action='store_true', default=False, + help='If set, verbose output is produced') args = parser.parse_args() source_root = args.src @@ -47,18 +54,22 @@ def main(): src_path = os.path.join(root, file) rel_path = os.path.relpath(src_path, source_root) dst_path = os.path.join(dest_root, rel_path) - tuple = (src_path, dst_path) - paths_list.append(tuple) + paths_list.append((src_path, dst_path)) with concurrent.futures.ProcessPoolExecutor() as executor: - futures = [ (executor.submit(preprocess_cssless.preprocess_html_merge_cssless, src_path, dst_path), i) - for i, (src_path, dst_path) in enumerate(paths_list) ] + futures = [ + executor.submit(preprocess_cssless.preprocess_html_merge_cssless, + src_path, dst_path) + for src_path, dst_path in paths_list + ] - for future, i in futures: - print('Processing file: {}/{}: {}'.format(i, len(paths_list), paths_list[i][1])) + for i, future in enumerate(futures): + print('Processing file: {}/{}: {}'.format( + i, len(paths_list), paths_list[i][1])) output = future.result() if verbose: print(output) + if __name__ == "__main__": main() diff --git a/requirements-ci.txt b/requirements-ci.txt new file mode 100644 index 000000000..176dc6285 --- /dev/null +++ b/requirements-ci.txt @@ -0,0 +1,2 @@ +pylint==2.6.0 +flake8==3.8.4 diff --git a/requirements.txt b/requirements.txt index 62b9b76d4..3731ef5df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -premailer -lxml +premailer==3.7.0 +lxml==4.9.1 diff --git a/test.sh b/test.sh index a8a93073f..e305304dd 100755 --- a/test.sh +++ b/test.sh @@ -1,3 +1,5 @@ #!/bin/sh +flake8 --config=config/flake8rc *.py commands index_transform gadgets/standard_revisions_tests/*.py tests +pylint --rcfile=config/pylintrc *.py commands index_transform gadgets/standard_revisions_tests/*.py tests python3 -m unittest discover "$@" diff --git a/tests/preprocess_data/fabs.html b/tests/preprocess_data/fabs.html index 0323f100a..c247287ee 100644 --- a/tests/preprocess_data/fabs.html +++ b/tests/preprocess_data/fabs.html @@ -2,17 +2,17 @@ std::abs(float), std::fabs - cppreference.com - - - - - - - - - - - + + + + + + + + + + + @@ -117,9 +117,9 @@
      @@ -148,8 +148,8 @@
      @@ -172,9 +172,9 @@
      Variants
      Views
      @@ -273,10 +273,10 @@

      From cppreference.com -
      < cpp‎ | numeric‎ | math
      +
      < cpp‎ | numeric‎ | math
      - +
       
      - + - + - + @@ -475,22 +475,22 @@

      -

      + - + - + - + @@ -526,6 +526,13 @@

      [[edit] Return value

      If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes.

      +
      +
      cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ifstreamcpp/io/basic istringstreamcpp/io/basic ostreamcpp/io/basic ofstreamcpp/io/basic ostringstreamcpp/io/basic fstreamcpp/io/basic stringstreamcpp/io/basic iostreamstd-io-complete-inheritance.svg
      About this image
      +
      +

      Inheritance diagram +

      +
      +

      [edit] Error handling

      This function is not subject to any of the error conditions specified in math_errhandling

      If the implementation supports IEEE floating-point arithmetic (IEC 60559), @@ -541,15 +548,15 @@

      [
      #include <iostream>
       #include <cmath>
      - 
      -int main()
      -{
      -    std::cout << "abs(+3.0) = " << std::abs(+3.0) << '\n'
      -              << "abs(-3.0) = " << std::abs(-3.0) << '\n';
      + 
      +int main()
      +{
      +    std::cout << "abs(+3.0) = " << std::abs(+3.0) << '\n'
      +              << "abs(-3.0) = " << std::abs(-3.0) << '\n';
           // special values
      -    std::cout << "abs(-0.0) = " << std::abs(-0.0) << '\n'
      -              << "abs(-Inf) = " << std::abs(-INFINITY) << '\n';
      -}
      + std::cout << "abs(-0.0) = " << std::abs(-0.0) << '\n' + << "abs(-Inf) = " << std::abs(-INFINITY) << '\n'; +}

      Possible output:

      abs(+3.0) = 3
      @@ -563,31 +570,31 @@ 

      [

      - - - - - @@ -613,7 +620,7 @@

      [https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/math/fabs&oldid=88521" - +
      @@ -651,7 +658,7 @@

      Toolbox
      @@ -678,4 +685,4 @@
      Toolbox
      - + \ No newline at end of file diff --git a/tests/preprocess_data/fabs_ads.html b/tests/preprocess_data/fabs_ads.html index 3e7fbaac6..2d34bcd46 100644 --- a/tests/preprocess_data/fabs_ads.html +++ b/tests/preprocess_data/fabs_ads.html @@ -462,6 +462,13 @@

      [[edit] Return value

      If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes.

      +
      +
      cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ifstreamcpp/io/basic istringstreamcpp/io/basic ostreamcpp/io/basic ofstreamcpp/io/basic ostringstreamcpp/io/basic fstreamcpp/io/basic stringstreamcpp/io/basic iostreamstd-io-complete-inheritance.svg
      About this image
      +
      +

      Inheritance diagram +

      +
      +

      [edit] Error handling

      This function is not subject to any of the error conditions specified in math_errhandling

      If the implementation supports IEEE floating-point arithmetic (IEC 60559), diff --git a/tests/preprocess_data/fabs_external.html b/tests/preprocess_data/fabs_external.html new file mode 100644 index 000000000..0c8a4f45d --- /dev/null +++ b/tests/preprocess_data/fabs_external.html @@ -0,0 +1,683 @@ + + + +std::abs(float), std::fabs - cppreference.com + + + + + + + + + + + + + + +

      +
      +
      +
      + cppreference.com
      + +
      + + + + + +
      + +
      +
      +
      +
      +
      + + +
      +
      Namespaces
      + +
      + + + + +
      +
      Variants
      + +
      + + +
      +
      + + +
      +
      Views
      + +
      + + + + +
      +
      Actions
      + +
      + + +
      +
      +
      +
      + + + +
      +
      + + + + +

      std::abs(float), std::fabs

      + + +
      + +
      From cppreference.com
      + + +
      < cpp‎ | numeric‎ | math
      + + +
      Defined in header <cmath> @@ -454,17 +454,17 @@

      (since C++17)

      float       abs( float arg );
      float       abs( float arg );
      (1)
      double      abs( double arg );
      double      abs( double arg );
      (2)
      long double abs( long double arg );
      long double abs( long double arg );
      (3)
      float       fabs( float arg );
      float       fabs( float arg );
      (4)
      double      fabs( double arg );
      double      fabs( double arg );
      (5)
      long double fabs( long double arg );
      long double fabs( long double arg );
      (6)
      double      fabs( Integral arg );
      double      fabs( Integral arg );
      (7) (since C++11)
      computes absolute value of an integral value (|x|)
      (function) [edit] +
      computes absolute value of an integral value (|x|)
      (function) [edit]
      (C++11)
      copies the sign of a floating point value
      (function) [edit] +
      copies the sign of a floating point value
      (function) [edit]
      (C++11)
      checks if the given number is negative
      (function) [edit] +
      checks if the given number is negative
      (function) [edit]
      returns the magnitude of a complex number
      (function template) [edit] +
      returns the magnitude of a complex number
      (function template) [edit]
      applies the function std::abs to each element of valarray
      (function template) [edit] +
      applies the function std::abs to each element of valarray
      (function template) [edit]
      + + + + + + + + + + + + + + + + + + + +
      Language
      Headers
      Named requirements
      Language support library
      Concepts library (C++20)
      Diagnostics library
      Utilities library
      Strings library
      Containers library
      Algorithms library
      Iterators library
      Numerics library
      Input/output library
      Localizations library
      Regular expressions library (C++11)
      Atomic operations library (C++11)
      Thread support library (C++11)
      Filesystem library (C++17)
      Technical Specifications
       
       
      Common mathematical functions
      +
      + + + + + + + + + +
      Functions
      Basic operations
      + + + + +
      abs(float)fabs
      + + + + + + + +
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)(C++11)(C++11)
      Exponential functions
      + + + +
      (C++11)
      (C++11)
      + + + + +
      (C++11)
      (C++11)
      Power functions
      + + +
      (C++11)
      + + +
      (C++11)
      Trigonometric and hyperbolic functions
      + + + + + + +
      (C++11)
      (C++11)
      (C++11)
      +
      +
      +
      + + + + + + + + + + +
      Error and gamma functions
      + + +
      (C++11)
      (C++11)
      + + +
      (C++11)
      (C++11)
      Nearest integer floating point operations
      + + + +
      (C++11)(C++11)(C++11)
      + + + +
      (C++11)
      (C++11)
      (C++11)(C++11)(C++11)
      Floating point manipulation functions
      + + + + +
      (C++11)(C++11)
      (C++11)
      (C++11)
      + + + + +
      (C++11)(C++11)
      (C++11)
      Classification/Comparison
      + + + + + + +
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      + + + + + + +
      (C++11)
      (C++11)
      Macro constants
      + +
      (C++11)(C++11)(C++11)(C++11)(C++11)
      +
       
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Defined in header <cmath> +
      Defined in header <cstdlib> +
      (since C++17)
      float       abs( float arg );
      (1)
      double      abs( double arg );
      (2)
      long double abs( long double arg );
      (3)
      Defined in header <cmath> +
      float       fabs( float arg );
      (4)
      double      fabs( double arg );
      (5)
      long double fabs( long double arg );
      (6)
      double      fabs( Integral arg );
      (7) (since C++11)
      +
      1-6) Computes the absolute value of a floating point value arg.
      +
      7) A set of overloads or a function template for all combinations of arguments of arithmetic type not covered by (4-6). If any argument has integral type, it is cast to double. If any other argument is long double, then the return type is long double, otherwise it is double.
      + + + +
      For integral arguments, the integral overloads of std::abs are likely better matches. If std::abs is called with an argument of type X such that std::is_unsigned<X>::value is true and X cannot be converted to int by integral promotion, the program is ill-formed.(since C++17)
      +

      Contents

      + +
      +

      [edit] Parameters

      + + + + + + +
      arg + - + Value of a floating-point or Integral type +
      +

      [edit] Return value

      +

      If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes. +

      +
      +
      cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ifstreamcpp/io/basic istringstreamcpp/io/basic ostreamcpp/io/basic ofstreamcpp/io/basic ostringstreamcpp/io/basic fstreamcpp/io/basic stringstreamcpp/io/basic iostreamstd-io-complete-inheritance.svg
      About this image
      +
      +

      Inheritance diagram +

      +
      +
      +

      [edit] Error handling

      +

      This function is not subject to any of the error conditions specified in math_errhandling +

      If the implementation supports IEEE floating-point arithmetic (IEC 60559), +

      +
      • If the argument is ±0, +0 is returned +
      • If the argument is ±∞, +∞ is returned +
      • If the argument is NaN, NaN is returned +
      +

      [edit] Notes

      +

      Between C++11 and C++14, the standard erroneously required std::abs to have overloads for integer types returning double. This requirement was removed in C++17 by defect report 2735. +

      +

      [edit] Example

      +
      +
      #include <iostream>
      +#include <cmath>
      + 
      +int main()
      +{
      +    std::cout << "abs(+3.0) = " << std::abs(+3.0) << '\n'
      +              << "abs(-3.0) = " << std::abs(-3.0) << '\n';
      +    // special values
      +    std::cout << "abs(-0.0) = " << std::abs(-0.0) << '\n'
      +              << "abs(-Inf) = " << std::abs(-INFINITY) << '\n';
      +}
      +

      Possible output: +

      +
      abs(+3.0) = 3
      +abs(-3.0) = 3
      +abs(-0.0) = 0
      +abs(-Inf) = inf
      +
      +

      [edit] See also

      + + + + + + + + + + + + + + + + + + + + + + + + + +
      + computes absolute value of an integral value (|x|)
      (function) [edit] +
      (C++11)
      +
      copies the sign of a floating point value
      (function) [edit] +
      (C++11)
      +
      checks if the given number is negative
      (function) [edit] +
      + returns the magnitude of a complex number
      (function template) [edit] +
      + applies the function std::abs to each element of valarray
      (function template) [edit] +
      +
      + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/preprocess_data/fabs_fileinfo.html b/tests/preprocess_data/fabs_fileinfo.html new file mode 100644 index 000000000..339da884c --- /dev/null +++ b/tests/preprocess_data/fabs_fileinfo.html @@ -0,0 +1,688 @@ + + + +std::abs(float), std::fabs - cppreference.com + + + + + + + + + + + + + + + + + + + +
      +
      +
      +
      + cppreference.com
      + +
      + + + + + +
      + +
      +
      +
      +
      +
      + + +
      +
      Namespaces
      + +
      + + + + +
      +
      Variants
      + +
      + + +
      +
      + + +
      +
      Views
      + +
      + + + + +
      +
      Actions
      + +
      + + +
      +
      +
      +
      + + + +
      +
      + + + + +

      std::abs(float), std::fabs

      + + +
      + +
      From cppreference.com
      + + +
      < cpp‎ | numeric‎ | math
      + + +
       
       
       
      Common mathematical functions
      +
      + + + + + + + + + +
      Functions
      Basic operations
      + + + + +
      abs(float)fabs
      + + + + + + + +
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)(C++11)(C++11)
      Exponential functions
      + + + +
      (C++11)
      (C++11)
      + + + + +
      (C++11)
      (C++11)
      Power functions
      + + +
      (C++11)
      + + +
      (C++11)
      Trigonometric and hyperbolic functions
      + + + + + + +
      (C++11)
      (C++11)
      (C++11)
      +
      +
      +
      + + + + + + + + + + +
      Error and gamma functions
      + + +
      (C++11)
      (C++11)
      + + +
      (C++11)
      (C++11)
      Nearest integer floating point operations
      + + + +
      (C++11)(C++11)(C++11)
      + + + +
      (C++11)
      (C++11)
      (C++11)(C++11)(C++11)
      Floating point manipulation functions
      + + + + +
      (C++11)(C++11)
      (C++11)
      (C++11)
      + + + + +
      (C++11)(C++11)
      (C++11)
      Classification/Comparison
      + + + + + + +
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      + + + + + + +
      (C++11)
      (C++11)
      Macro constants
      + +
      (C++11)(C++11)(C++11)(C++11)(C++11)
      +
       
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Defined in header <cmath> +
      Defined in header <cstdlib> +
      (since C++17)
      float       abs( float arg );
      (1)
      double      abs( double arg );
      (2)
      long double abs( long double arg );
      (3)
      Defined in header <cmath> +
      float       fabs( float arg );
      (4)
      double      fabs( double arg );
      (5)
      long double fabs( long double arg );
      (6)
      double      fabs( Integral arg );
      (7) (since C++11)
      +
      1-6) Computes the absolute value of a floating point value arg.
      +
      7) A set of overloads or a function template for all combinations of arguments of arithmetic type not covered by (4-6). If any argument has integral type, it is cast to double. If any other argument is long double, then the return type is long double, otherwise it is double.
      + + + +
      For integral arguments, the integral overloads of std::abs are likely better matches. If std::abs is called with an argument of type X such that std::is_unsigned<X>::value is true and X cannot be converted to int by integral promotion, the program is ill-formed.(since C++17)
      +

      Contents

      + +
      +

      [edit] Parameters

      + + + + + + +
      arg + - + Value of a floating-point or Integral type +
      +

      [edit] Return value

      +

      If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes. +

      +
      +
      cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ifstreamcpp/io/basic istringstreamcpp/io/basic ostreamcpp/io/basic ofstreamcpp/io/basic ostringstreamcpp/io/basic fstreamcpp/io/basic stringstreamcpp/io/basic iostreamstd-io-complete-inheritance.svg
      +
      +

      Inheritance diagram +

      +
      +
      +

      [edit] Error handling

      +

      This function is not subject to any of the error conditions specified in math_errhandling +

      If the implementation supports IEEE floating-point arithmetic (IEC 60559), +

      +
      • If the argument is ±0, +0 is returned +
      • If the argument is ±∞, +∞ is returned +
      • If the argument is NaN, NaN is returned +
      +

      [edit] Notes

      +

      Between C++11 and C++14, the standard erroneously required std::abs to have overloads for integer types returning double. This requirement was removed in C++17 by defect report 2735. +

      +

      [edit] Example

      +
      +
      #include <iostream>
      +#include <cmath>
      + 
      +int main()
      +{
      +    std::cout << "abs(+3.0) = " << std::abs(+3.0) << '\n'
      +              << "abs(-3.0) = " << std::abs(-3.0) << '\n';
      +    // special values
      +    std::cout << "abs(-0.0) = " << std::abs(-0.0) << '\n'
      +              << "abs(-Inf) = " << std::abs(-INFINITY) << '\n';
      +}
      +

      Possible output: +

      +
      abs(+3.0) = 3
      +abs(-3.0) = 3
      +abs(-0.0) = 0
      +abs(-Inf) = inf
      +
      +

      [edit] See also

      + + + + + + + + + + + + + + + + + + + + + + + + + +
      + computes absolute value of an integral value (|x|)
      (function) [edit] +
      (C++11)
      +
      copies the sign of a floating point value
      (function) [edit] +
      (C++11)
      +
      checks if the given number is negative
      (function) [edit] +
      + returns the magnitude of a complex number
      (function template) [edit] +
      + applies the function std::abs to each element of valarray
      (function template) [edit] +
      +
      + + + + +
      + + + + + +
      + + +
      + +
      +
      + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/preprocess_data/fabs_ga.html b/tests/preprocess_data/fabs_ga.html index 6996631b1..334e170a2 100644 --- a/tests/preprocess_data/fabs_ga.html +++ b/tests/preprocess_data/fabs_ga.html @@ -526,6 +526,13 @@

      [[edit] Return value

      If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes.

      +
      +
      cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ifstreamcpp/io/basic istringstreamcpp/io/basic ostreamcpp/io/basic ofstreamcpp/io/basic ostringstreamcpp/io/basic fstreamcpp/io/basic stringstreamcpp/io/basic iostreamstd-io-complete-inheritance.svg
      About this image
      +
      +

      Inheritance diagram +

      +
      +

      [edit] Error handling

      This function is not subject to any of the error conditions specified in math_errhandling

      If the implementation supports IEEE floating-point arithmetic (IEC 60559), diff --git a/tests/preprocess_data/fabs_noprint.html b/tests/preprocess_data/fabs_noprint.html index 3f146bd5c..c83cd6eee 100644 --- a/tests/preprocess_data/fabs_noprint.html +++ b/tests/preprocess_data/fabs_noprint.html @@ -428,6 +428,13 @@

      Parameters

      Return value

      If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes.

      +
      +
      cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ifstreamcpp/io/basic istringstreamcpp/io/basic ostreamcpp/io/basic ofstreamcpp/io/basic ostringstreamcpp/io/basic fstreamcpp/io/basic stringstreamcpp/io/basic iostreamstd-io-complete-inheritance.svg
      About this image
      +
      +

      Inheritance diagram +

      +
      +

      Error handling

      This function is not subject to any of the error conditions specified in math_errhandling

      If the implementation supports IEEE floating-point arithmetic (IEC 60559), diff --git a/tests/preprocess_data/fabs_seealso.html b/tests/preprocess_data/fabs_seealso.html index 9e669b115..1b968ed3b 100644 --- a/tests/preprocess_data/fabs_seealso.html +++ b/tests/preprocess_data/fabs_seealso.html @@ -526,6 +526,13 @@

      [[edit] Return value

      If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes.

      +
      +
      cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ifstreamcpp/io/basic istringstreamcpp/io/basic ostreamcpp/io/basic ofstreamcpp/io/basic ostringstreamcpp/io/basic fstreamcpp/io/basic stringstreamcpp/io/basic iostreamstd-io-complete-inheritance.svg
      About this image
      +
      +

      Inheritance diagram +

      +
      +

      [edit] Error handling

      This function is not subject to any of the error conditions specified in math_errhandling

      If the implementation supports IEEE floating-point arithmetic (IEC 60559), @@ -590,10 +597,6 @@

      [std::abs to each element of valarray
      (function template)
      [edit] - - - -