C++ header files download






















The following screen will appear after the import is successful. To start using the model, select Kotlin or Java, copy and paste the code under the Sample Code section. You can get back to this screen by double clicking the TFLite model under the ml directory in Android Studio.

It provides optimized out-of-box model interfaces for popular machine learning tasks, such as image classification, question and answer, etc. The model interfaces are specifically designed for each task to achieve the best performance and usability. You can specify this in your build. To use nightly snapshots, make sure that you have added Sonatype snapshot repository.

It provides high-level APIs that help transform raw input data into the form required by the model, and interpret the model's output, reducing the amount of boilerplate code required. It supports common data formats for inputs and outputs, including images and arrays. It also provides pre- and post-processing units that perform tasks such as image resizing and cropping.

You can reduce the size of your application's binary by only including the ABIs you need to support. This can be achieved with the following Gradle configuration, which specifically includes only armeabi-v7a and armv8a , which should cover most modern Android devices. This is the recommended approach. Additionally, you will need header files from FlatBuffers and Abseil.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4. For details, see the Google Developers Site Policies. Install Learn Introduction.

Jul 28, Problem: sock. Oct 21, Problem: whitespace style too restrictive. May 12, Problem: Only one build directory ignored. Jun 27, Added license and link to C4. May 10, Oct 25, Problem: cppzmq fails with cmake 3.

Jul 4, Sep 11, View code. You only need to include the header file zmq. In particular, none of the following bindings are header-only: zmqpp is a high-level binding to libzmq. Supported platforms Only a subset of the platforms that are supported by libzmq itself are supported. To build and run the tests, CMake and Catch are required. Any libzmq 4. You may use noexcept when it is useful for performance if it accurately reflects the intended semantics of your function, i.

You can assume that noexcept on move constructors has a meaningful performance benefit. If you think there is significant performance benefit from specifying noexcept on some other function, please discuss it with your project leads. Prefer unconditional noexcept if exceptions are completely disabled i. Otherwise, use conditional noexcept specifiers with simple conditions, in ways that evaluate false only in the few cases where the function could potentially throw.

The tests might include type traits check on whether the involved operation might throw e. The standard alternatives to RTTI described below require modification or redesign of the class hierarchy in question. Sometimes such modifications are infeasible or undesirable, particularly in widely-used or mature code.

RTTI can be useful in some unit tests. For example, it is useful in tests of factory classes where the test has to verify that a newly created object has the expected dynamic type. It is also useful in managing the relationship between objects and their mocks. Querying the type of an object at run-time frequently means a design problem. Needing to know the type of an object at runtime is often an indication that the design of your class hierarchy is flawed.

Undisciplined use of RTTI makes code hard to maintain. It can lead to type-based decision trees or switch statements scattered throughout the code, all of which must be examined when making further changes. RTTI has legitimate uses but is prone to abuse, so you must be careful when using it. You may use it freely in unittests, but avoid it when possible in other code. In particular, think twice before using RTTI in new code. If you find yourself needing to write code that behaves differently based on the class of an object, consider one of the following alternatives to querying the type:.

Code such as this usually breaks when additional subclasses are added to the class hierarchy. Moreover, when properties of a subclass change, it is difficult to find and modify all the affected code segments.

Do not hand-implement an RTTI-like workaround. The arguments against RTTI apply just as much to workarounds like class hierarchies with type tags. Moreover, workarounds disguise your true intent. Do not use cast formats like int x unless the cast is to void. The problem with C casts is the ambiguity of the operation; sometimes you are doing a conversion e. In general, do not use C-style casts.

Use streams where appropriate, and stick to "simple" usages. They are widely used in Google code, mostly for debug logging and test diagnostics. The C APIs do as well, but are hampered by the need to manually buffer the input. Use streams only when they are the best tool for the job. Be consistent with the code around you, and with the codebase as a whole; if there's an established tool for your problem, use that tool instead.

Instead, find and use the appropriate templating libraries to handle issues like internationalization, localization, and security hardening.

Use explicit formatting functions such as absl::StreamFormat rather than stream manipulators or formatting flags to control formatting details such as number base, precision, or padding. This can result in code that is more compact but harder to read. The prefix form is generally more readable, is never less efficient, and can be more efficient because it doesn't need to make a copy of the value as it was before the operation. The tradition developed, in C, of using post-increment, even when the expression value is not used, especially in for loops.

In APIs, use const whenever it makes sense. Declared variables and parameters can be preceded by the keyword const to indicate the variables are not changed e. Class functions can have the const qualifier to indicate the function does not change the state of the class member variables e. Easier for people to understand how variables are being used. Allows the compiler to do better type checking, and, conceivably, generate better code. Helps people convince themselves of program correctness because they know the functions they call are limited in how they can modify your variables.

Helps people know what functions are safe to use without locks in multi-threaded programs. This can be a particular problem when calling library functions. We strongly recommend using const in APIs i. This provides consistent, mostly compiler-verified documentation of what objects an operation can mutate. Having a consistent and reliable way to distinguish reads from writes is critical to writing thread-safe code, and is useful in many other contexts as well.

In particular:. All of a class's const operations should be safe to invoke concurrently with each other. If that's not feasible, the class must be clearly documented as "thread-unsafe".

They argue that this is more readable because it's more consistent: it keeps the rule that const always follows the object it's describing. However, this consistency argument doesn't apply in codebases with few deeply-nested pointer expressions since most const expressions have only one const , and it applies to the underlying value. In such cases, there's no consistency to maintain. Putting the const first is arguably more readable, since it follows English in putting the "adjective" const before the "noun" int.

That said, while we encourage putting const first, we do not require it. But be consistent with the code around you! Some variables can be declared constexpr to indicate the variables are true constants, i. Some functions and constructors can be declared constexpr which enables them to be used in defining a constexpr variable. Use of constexpr enables definition of constants with floating-point expressions rather than just literals; definition of constants of user-defined types; and definition of constants with function calls.

Prematurely marking something as constexpr may cause migration problems if later on it has to be downgraded. Current restrictions on what is allowed in constexpr functions and constructors may invite obscure workarounds in these definitions. Use constexpr to specify true constants and the functions that support their definitions. Avoid complexifying function definitions to enable their use with constexpr.

Do not use constexpr to force inlining. Keep in mind that even if your value won't ever be too large for an int , it may be used in intermediate calculations which may require a larger type. When in doubt, choose a larger type. Typically people assume that short is 16 bits, int is 32 bits, long is 32 bits and long long is 64 bits.

We use int very often, for integers we know are not going to be too big, e. Use plain old int for such things. You should assume that an int is at least 32 bits, but don't assume that it has more than 32 bits. In particular, do not use unsigned types to say a number will never be negative. Instead, use assertions for this. If your code is a container that returns a size, be sure to use a type that will accommodate any possible usage of your container.

When in doubt, use a larger type rather than a smaller type. Use care when converting integer types. Integer conversions and promotions can cause undefined behavior, leading to security bugs and other problems. Unsigned integers are good for representing bitfields and modular arithmetic.

In other cases, the defined behavior impedes optimization. That said, mixing signedness of integer types is responsible for an equally large class of problems. The best advice we can provide: try to use iterators and containers rather than pointers and sizes, try not to mix signedness, and try to avoid unsigned types except for representing bitfields or modular arithmetic.

Do not use an unsigned type merely to assert that a variable is non-negative. Code should be bit and bit friendly. Bear in mind problems of printing, comparisons, and structure alignment. Unless there is no reasonable alternative for your particular case, try to avoid or even upgrade APIs that rely on the printf family. Instead use a library supporting typesafe numeric formatting, such as StrCat or Substitute for fast simple conversions, or std::ostream. Unfortunately, the PRI macros are the only portable way to specify a conversion for the standard bitwidth typedefs e.

Where possible, avoid passing arguments of types specified by bitwidth typedefs to printf -based APIs. Use braced-initialization as needed to create bit constants. Avoid defining macros, especially in headers; prefer inline functions, enums, and const variables.

Name macros with a project-specific prefix. Macros mean that the code you see is not the same as the code the compiler sees. This can introduce unexpected behavior, especially since macros have global scope. Every error message from the compiler when developers incorrectly use that interface now must explain how the macros formed the interface.

Refactoring and analysis tools have a dramatically harder time updating the interface. As a consequence, we specifically disallow using macros in this way. For example, avoid patterns like:. Instead of using a macro to inline performance-critical code, use an inline function.

Instead of using a macro to store a constant, use a const variable. Instead of using a macro to "abbreviate" a long variable name, use a reference. Instead of using a macro to conditionally compile code It makes testing much more difficult. Macros can do things these other techniques cannot, and you do see them in the codebase, especially in the lower-level libraries. And some of their special features like stringifying, concatenation, and so forth are not available through the language proper.

But before using a macro, consider carefully whether there's a non-macro way to achieve the same result. If you need to use a macro to define an interface, contact your project leads to request a waiver of this rule. The following usage pattern will avoid many problems with macros; if you use macros, follow it whenever possible:. Exporting macros from headers i. If you do export a macro from a header, it must have a globally unique name. To achieve this, it must be named with a prefix consisting of your project's namespace name but upper case.

Never use NULL for numeric integer or floating-point values. Using the correct type makes the code more readable. Use sizeof varname when you take the size of a particular variable.

Use type deduction only if it makes the code clearer to readers who aren't familiar with the project, or if it makes the code safer. Do not use it merely to avoid the inconvenience of writing an explicit type. In expressions like:. Programmers have to understand when type deduction will or won't produce a reference type, or they'll get copies when they didn't mean to.

If a deduced type is used as part of an interface, then a programmer might change its type while only intending to change its value, leading to a more radical API change than intended. The fundamental rule is: use type deduction only to make the code clearer or safer, and do not use it merely to avoid the inconvenience of writing an explicit type.

When judging whether the code is clearer, keep in mind that your readers are not necessarily on your team, or familiar with your project, so types that you and your reviewer experience as unnecessary clutter will very often provide useful information to others. These principles apply to all forms of type deduction, but the details vary, as described in the following sections. Function template argument deduction is almost always OK. Type deduction is the expected default way of interacting with function templates, because it allows function templates to act like infinite sets of ordinary function overloads.

Consequently, function templates are almost always designed so that template argument deduction is clear and safe, or doesn't compile.

For local variables, you can use type deduction to make the code clearer by eliminating type information that is obvious or irrelevant, so that the reader can focus on the meaningful parts of the code:.

Types sometimes contain a mixture of useful information and boilerplate, such as it in the example above: it's obvious that the type is an iterator, and in many contexts the container type and even the key type aren't relevant, but the type of the values is probably useful.

In such situations, it's often possible to define local variables with explicit types that convey the relevant information:. If the type is a template instance, and the parameters are boilerplate but the template itself is informative, you can use class template argument deduction to suppress the boilerplate.

However, cases where this actually provides a meaningful benefit are quite rare. Note that class template argument deduction is also subject to a separate style rule. Do not use decltype auto if a simpler option will work, because it's a fairly obscure feature, so it has a high cost in code clarity.

Use return type deduction for both functions and lambdas only if the function body has a very small number of return statements, and very little other code, because otherwise the reader may not be able to tell at a glance what the return type is.

Furthermore, use it only if the function or lambda has a very narrow scope, because functions with deduced return types don't define abstraction boundaries: the implementation is the interface. In particular, public functions in header files should almost never have deduced return types.

Consequently, an explicit type will almost always be clearer unless the lambda is explicitly called very close to where it's defined so that the reader can easily see both , or the lambda is passed to an interface so well-known that it's obvious what arguments it will eventually be called with e. Init captures are covered by a more specific style rule , which largely supersedes the general rules for type deduction. Unlike other forms of type deduction, structured bindings can actually give the reader additional information, by giving meaningful names to the elements of a larger object.

This means that a structured binding declaration may provide a net readability improvement over an explicit type, even in cases where auto would not. Structured bindings are especially beneficial when the object is a pair or tuple as in the insert example above , because they don't have meaningful field names to begin with, but note that you generally shouldn't use pairs or tuples unless a pre-existing API like insert forces you to.

If the object being bound is a struct, it may sometimes be helpful to provide names that are more specific to your usage, but keep in mind that this may also mean the names are less recognizable to your reader than the field names.

We recommend using a comment to indicate the name of the underlying field, if it doesn't match the name of the binding, using the same syntax as for function parameter comments:. As with function parameter comments, this can enable tools to detect if you get the order of the fields wrong. Use class template argument deduction only with templates that have explicitly opted into supporting it. Class template argument deduction often abbreviated "CTAD" occurs when a variable is declared with a type that names a template, and the template argument list is not provided not even empty angle brackets :.

The compiler deduces the arguments from the initializer using the template's "deduction guides", which can be explicit or implicit.

Explicit deduction guides look like function declarations with trailing return types, except that there's no leading auto , and the function name is the name of the template. For example, the above example relies on this deduction guide for std::array :.

Constructors in a primary template as opposed to a template specialization also implicitly define deduction guides. When you declare a variable that relies on CTAD, the compiler selects a deduction guide using the rules of constructor overload resolution, and that guide's return type becomes the type of the variable.

The implicit deduction guides that are generated from constructors may have undesirable behavior, or be outright incorrect. Furthermore, adding explicit deduction guides to fix those problems might break any existing code that relies on the implicit deduction guides. CTAD also suffers from many of the same drawbacks as auto , because they are both mechanisms for deducing all or part of a variable's type from its initializer. CTAD does give the reader more information than auto , but it also doesn't give the reader an obvious cue that information has been omitted.

Do not use CTAD with a given template unless the template's maintainers have opted into supporting use of CTAD by providing at least one explicit deduction guide all templates in the std namespace are also presumed to have opted in. This should be enforced with a compiler warning if available.

Designated initializers are a syntax that allows for initializing an aggregate "plain old struct" by naming its fields explicitly:. Designated initializers can make for convenient and highly readable aggregate expressions, especially for structs with less straightforward ordering of fields than the Point example above.

Use lambda expressions where appropriate. Prefer explicit captures when the lambda will escape the current scope. Lambda expressions are a concise way of creating anonymous function objects.

They're often useful when passing functions as arguments. They further allow capturing variables from the enclosing scope either explicitly by name, or implicitly using a default capture.

Explicit captures require each variable to be listed, as either a value or reference capture:. Default captures implicitly capture any variable referenced in the lambda body, including this if any members are used:. A variable capture can also have an explicit initializer, which can be used for capturing move-only variables by value, or for other situations not handled by ordinary reference or value captures:.

Such captures often called "init captures" or "generalized lambda captures" need not actually "capture" anything from the enclosing scope, or even have a name from the enclosing scope; this syntax is a fully general way to define members of a lambda object:.

The type of a capture with an initializer is deduced using the same rules as auto. Template metaprogramming allows extremely flexible interfaces that are type safe and high performance. Facilities like GoogleTest , std::tuple , std::function , and Boost. Spirit would be impossible without it. The techniques used in template metaprogramming are often obscure to anyone but language experts. Code that uses templates in complicated ways is often unreadable, and is hard to debug or maintain. Template metaprogramming often leads to extremely poor compile time error messages: even if an interface is simple, the complicated implementation details become visible when the user does something wrong.

Template metaprogramming interferes with large scale refactoring by making the job of refactoring tools harder. First, the template code is expanded in multiple contexts, and it's hard to verify that the transformation makes sense in all of them.

Second, some refactoring tools work with an AST that only represents the structure of the code after template expansion.

It can be difficult to automatically work back to the original source construct that needs to be rewritten. Template metaprogramming sometimes allows cleaner and easier-to-use interfaces than would be possible without it, but it's also often a temptation to be overly clever.

It's best used in a small number of low level components where the extra maintenance burden is spread out over a large number of uses. If you're using recursive template instantiations or type lists or metafunctions or expression templates, or relying on SFINAE or on the sizeof trick for detecting function overload resolution, then there's a good chance you've gone too far.

If you use template metaprogramming, you should expect to put considerable effort into minimizing and isolating the complexity. You should hide metaprogramming as an implementation detail whenever possible, so that user-facing headers are readable, and you should make sure that tricky code is especially well commented.

You should carefully document how the code is used, and you should say something about what the "generated" code looks like. Pay extra attention to the error messages that the compiler emits when users make mistakes.

The error messages are part of your user interface, and your code should be tweaked as necessary so that the error messages are understandable and actionable from a user point of view. Some Boost libraries encourage coding practices which can hamper readability, such as metaprogramming and other advanced template techniques, and an excessively "functional" style of programming. In order to maintain a high level of readability for all contributors who might read and maintain code, we only allow an approved subset of Boost features.

Currently, the following libraries are permitted:. We are actively considering adding other Boost features to the list, so this list may be expanded in the future. Other extensions duplicate functionality available through existing mechanisms, which may lead to confusion and conversion costs. Do not use nonstandard extensions. You may use portability wrappers that are implemented using nonstandard extensions, so long as those wrappers are provided by a designated project-wide portability header.

Like other declarations, aliases declared in a header file are part of that header's public API unless they're in a function definition, in the private portion of a class, or in an explicitly-marked internal namespace.

Aliases in such areas or in. Don't put an alias in your public API just to save typing in the implementation; do so only if you intend it to be used by your clients. When defining a public alias, document the intent of the new name, including whether it is guaranteed to always be the same as the type it's currently aliased to, or whether a more limited compatibility is intended.

This lets the user know whether they can treat the types as substitutable or whether more specific rules must be followed, and can help the implementation retain some degree of freedom to change the alias.

However, local convenience aliases are fine in function definitions, private sections of classes, explicitly marked internal namespaces, and in. In all code, including naming and comments, use inclusive language and avoid terms that other programmers might find disrespectful or offensive such as "master" and "slave", "blacklist" and "whitelist", or "redline" , even if the terms also have an ostensibly neutral meaning.

Similarly, use gender-neutral language unless you're referring to a specific person and using their pronouns. The most important consistency rules are those that govern naming. The style of a name immediately informs us what sort of thing the named entity is: a type, a variable, a function, a constant, a macro, etc. The pattern-matching engine in our brains relies a great deal on these naming rules. Naming rules are pretty arbitrary, but we feel that consistency is more important than individual preferences in this area, so regardless of whether you find them sensible or not, the rules are the rules.

Use names that describe the purpose or intent of the object. Do not worry about saving horizontal space as it is far more important to make your code immediately understandable by a new reader. Minimize the use of abbreviations that would likely be unknown to someone outside your project especially acronyms and initialisms. Do not abbreviate by deleting letters within a word. As a rule of thumb, an abbreviation is probably OK if it's listed in Wikipedia. Generally speaking, descriptiveness should be proportional to the name's scope of visibility.

For example, n may be a fine name within a 5-line function, but within the scope of a class, it's likely too vague. Note that certain universally-known abbreviations are OK, such as i for an iteration variable and T for a template parameter. For the purposes of the naming rules below, a "word" is anything that you would write in English without internal spaces. This includes abbreviations, such as acronyms and initialisms. For names written in mixed case also sometimes referred to as " camel case " or " Pascal case " , in which the first letter of each word is capitalized, prefer to capitalize abbreviations as single words, e.

Template parameters should follow the naming style for their category: type template parameters should follow the rules for type names , and non-type template parameters should follow the rules for variable names. Follow the convention that your project uses. Files that rely on being textually included at specific points should end in. In general, make your filenames very specific. A very common case is to have a pair of files called, e. Type names start with a capital letter and have a capital letter for each new word, with no underscores: MyExcitingClass , MyExcitingEnum.

The names of all types — classes, structs, type aliases, enums, and type template parameters — have the same naming convention. Type names should start with a capital letter and have a capital letter for each new word. No underscores. The names of variables including function parameters and data members are all lowercase, with underscores between words.

Data members of classes but not structs additionally have trailing underscores. Data members of classes, both static and non-static, are named like ordinary nonmember variables, but with a trailing underscore. Data members of structs, both static and non-static, are named like ordinary nonmember variables.

They do not have the trailing underscores that data members in classes have. See Structs vs. Classes for a discussion of when to use a struct versus a class. Variables declared constexpr or const, and whose value is fixed for the duration of the program, are named with a leading "k" followed by mixed case.

Underscores can be used as separators in the rare cases where capitalization cannot be used for separation. All such variables with static storage duration i. This convention is optional for variables of other storage classes, e. Ordinarily, functions should start with a capital letter and have a capital letter for each new word. The same naming rule applies to class- and namespace-scope constants that are exposed as part of an API and that are intended to look like functions, because the fact that they're objects rather than functions is an unimportant implementation detail.

Accessors and mutators get and set functions may be named like variables. These often correspond to actual member variables, but this is not required. The name of a top-level namespace should usually be the name of the project or team whose code is contained in that namespace. The code in that namespace should usually be in a directory whose basename matches the namespace name or in subdirectories thereof.

Keep in mind that the rule against abbreviated names applies to namespaces just as much as variable names. Code inside the namespace seldom needs to mention the namespace name, so there's usually no particular need for abbreviation anyway. Avoid nested namespaces that match well-known top-level namespaces.

Collisions between namespace names can lead to surprising build breaks because of name lookup rules. In particular, do not create any nested std namespaces. Also avoid overly deep nesting namespaces TotW For internal namespaces, be wary of other code being added to the same internal namespace causing a collision internal helpers within a team tend to be related and may lead to collisions.

Enumerators for both scoped and unscoped enums should be named like constants , not like macros. Until January , the style was to name enum values like macros. This caused problems with name collisions between enum values and macros.



0コメント

  • 1000 / 1000