C++98 Mapping for Built-In Types
On this page:
Mapping of Slice Built-In Types to C++ Types
The Slice built-in types are mapped to C++ types as shown in this table:
Slice | C++ |
---|---|
bool |
|
byte |
|
short |
|
int |
|
long |
|
float |
|
double |
|
string |
|
Ice::Byte
is a typedef for unsigned char
. This guarantees that byte values are always in the range 0..255.
All the basic types are guaranteed to be distinct C++ types, that is, you can safely overload functions that differ in only the types listed in the table above.
Alternative String Mapping for C++
You can use a metadata directive, "cpp:type:wstring"
, to map strings to C++ std::wstring
. For containers (such as interfaces or structures), the metadata directive applies to all strings within the container. A corresponding metadata directive, "cpp:type:string"
, can be used to selectively override the mapping defined by the enclosing container. For example:
["cpp:type:wstring"] struct S1 { string x; // Maps to std::wstring ["cpp:type:wstring"] string y; // Maps to std::wstring ["cpp:type:string"] string z; // Maps to std::string } struct S2 { string x; // Maps to std::string ["cpp:type:string"] string y; // Maps to std::string ["cpp:type:wstring"] string z; // Maps to std::wstring }
With these metadata directives, the strings are mapped as indicated by the comments. By default, narrow strings are encoded as UTF-8, and wide strings use a UTF encoding that is appropriate for the platform on which the application executes. You can override the encoding for narrow and wide strings by registering a string converter with the Ice run time.
String View Mapping in C++
You can use the metadata directive cpp:view-type:string-view-type
to map some string parameters to a custom C++ "view-type" of your choice. This view-type can reference memory without owning it, like the experimental string_view
type. For example:
void sendString(["cpp:view-type:std::experimental::string_view"] string data);
maps to:
// Proxy function for synchronous call: input parameter mapped to string_view type. void sendString(const std::experimental::string_view&);
See Customizing the C++98 Mapping for a detailed description of the cpp:view-type
metadata directive.
See Also
- Basic Types
- Customizing the C++98 Mapping
- C++98 Mapping for Identifiers
- C++98 Mapping for Modules
- C++98 Mapping for Enumerations
- C++98 Mapping for Structures
- C++98 Mapping for Sequences
- C++98 Mapping for Dictionaries
- C++98 Mapping for Constants
- C++98 Mapping for Exceptions
- C++98 Strings and Character Encoding