Preliminary documentation for Ice for MATLAB. Do not use in production applications. Refer to the space directory for other releases.

Slice constant definitions map to corresponding C++ constant definitions. Slice constants are mapped to constexpr constants whenever possible, and to const constants otherwise. For example:

Slice
const bool      AppendByDefault = true;
const byte      LowerNibble = 0x0f;
const string    Advice = "Don't Panic!";
const short     TheAnswer = 42;
const double    PI = 3.1416;

enum Fruit { Apple, Pear, Orange }
const Fruit     FavoriteFruit = Pear;

Here are the generated C++ definitions for these constants:

C++
constexpr bool          AppendByDefault = true;
constexpr Ice::Byte     LowerNibble =     15;
constexpr std::string   Advice =          "Don't Panic!";
constexpr short         TheAnswer =       42;
constexpr double        PI =              3.1416;

enum class Fruit : unsigned char { Apple, Pear, Orange };
constexpr Fruit         FavoriteFruit =   Fruit::Pear;

All constants are initialized directly in the header file, so they are compile-time constants and can be used in contexts where a compile-time constant expression is required, such as to dimension an array or as the case label of a switch statement.

A Slice string literal that contains non-ASCII characters is mapped by default to a narrow C++ string literal (UTF-8 encoded) with the non-ASCII characters replaced by the corresponding universal character names. For example:

Slice
const string Egg = "œuf"; 

is mapped to:

C++
constexpr std::string Egg = u8"\u0153uf";

If you map a string constant to a std::wstring, the non-ASCII characters in the string literal are likewise replaced by universal character names. For example:

Slice
const ["cpp:type:wstring"] string LargeEgg = "gros œuf"; 

is mapped to:

C++
constexpr std::wstring LargeEgg = L"gros \u0153uf";

A Slice string literal that contains universal character names is mapped to a narrow C++ string (UTF-8 encoded) or to a wide C++ string with the universal character names preserved. For example:

Slice
const string Heart = "c\u0153ur";
const ["cpp:type:wstring"] string BigHeart = "grand c\u0153ur"; 
const ["cpp:type:wstring"] string Banana = "\U0001F34C";

is mapped to:

C++
constexpr std::string Heart = u8"c\u0153ur";
constexpr std::wstring BigHeart = L"grand c\u0153ur";
constexpr std::wstring Banana = L"\U0001F34C";

See Also

  • No labels