Skip to content

Dimous/alias

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

I Can't Believe
It's Not

C++!®

use alias::alias;

alias!(
    type string = String;
    type vector<T> = Vec<T>;
    type optional<T> = Option<T>;
    type result<T, E> = Result<T, E>;
    type shared_ptr<T> = std::sync::Arc<T>;
    type map<K, V> = std::collections::HashMap<K, V>;
);

fn get_database_value(id: i32) -> result<string, string> {
    if 42 == id {
        ok(string::from("Boost::Any"))
    } else {
        error(string::from("Not found"))
    }
}

fn main() {
    let mut names: vector<string> = vector::new();

    names.push(string::from("Boost::Any"));

    let pointer: shared_ptr<i32> = shared_ptr::new(100);
    let mut registry: map<string, shared_ptr<i32>> = map::new();

    registry.insert(string::from("key"), shared_ptr::clone(&pointer));

    let status = get_database_value(42);
    let none_val: optional<i32> = none();
    let some_val: optional<i32> = some(10);

    if status.is_ok() {
        println!("Value: {}, Shared: {}", status.unwrap(), *pointer);
    }

    if none_val.is_none() {
        println!("Optional is none as expected");
    }
}

About

Create type aliases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages