mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-17 22:03:07 -06:00
New Core Tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@10538 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dd88feaf2e
commit
6c22e727de
37 changed files with 3125 additions and 0 deletions
44
tutorial/CoreTutorial/Null.cpp
Normal file
44
tutorial/CoreTutorial/Null.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "Tutorial.h"
|
||||
|
||||
void NullTutorial()
|
||||
{
|
||||
/// .`Null`
|
||||
|
||||
/// U++ defines a special `Null` constant to represent an empty value. This constant is
|
||||
/// convertible to many value types including primitive types `double`, `int` and `int64`
|
||||
/// (defined as lowest number the type can represent). If type supports ordering (<, >),
|
||||
/// all values of the type are greater than Null value. To test whether a value is empty,
|
||||
/// use `IsNull` function.
|
||||
|
||||
int x = Null;
|
||||
int y = 120;
|
||||
Date d = Null;
|
||||
Date e = GetSysDate();
|
||||
|
||||
DUMP(x);
|
||||
DUMP(y);
|
||||
DUMP(d);
|
||||
DUMP(e > d);
|
||||
|
||||
/// Null is the only instance of `Nuller` type. Assigning `Null` to
|
||||
/// primitive types is achieved by cast operators of `Nuller`, other types can do it using
|
||||
/// constructor from `Nuller`.
|
||||
|
||||
/// As a special case, if Value contains Null, it is convertible to any value type that can contain Null:
|
||||
|
||||
Value v = x; // x is int
|
||||
e = v; // e is Date, but v is Null, so Null is assigned to e
|
||||
|
||||
DUMP(IsNull(e));
|
||||
|
||||
/// Function `Nvl` is U++ analog of well known SQL function coalesce (ifnull, Nvl), which
|
||||
/// returns the first non-null argument (or `Null` if all are `Null`).
|
||||
|
||||
int a = Null;
|
||||
int b = 123;
|
||||
int c = 1;
|
||||
|
||||
DUMP(Nvl(a, b, c));
|
||||
|
||||
///
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue