Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move]Support method to determine two generic type are equal #3178

Closed
element2050 opened this issue Jan 27, 2022 · 2 comments
Closed

[move]Support method to determine two generic type are equal #3178

element2050 opened this issue Jan 27, 2022 · 2 comments

Comments

@element2050
Copy link

Stdlib can determine two token type are equal, it depends native method name_of .

    /// Return true if the type `TokenType1` is same with `TokenType2`
    public fun is_same_token<TokenType1: store, TokenType2: store>(): bool {
        return token_code<TokenType1>() == token_code<TokenType2>()
    }

Can support method to determine any generic type are equals ? Likes

Generic Type1 == Generic Type2 ? 
@jolestar
Copy link
Member

Using a Global Registry is one way to achieve this, like the NFT.

public fun is_same_type<T1,T2>():bool{
   let type_info_1 = borrow_global<TypeInfo<T1>>();
   let type_info_2 = borrow_global<TypeInfo<T2>>();
   return type_info_1 == type_info_2;
}

@jolestar jolestar changed the title Support method to determine two generic type are equal [move]Support method to determine two generic type are equal Mar 21, 2022
@jolestar
Copy link
Member

This feature has been supported in StarcoinFramework by starcoinorg/starcoin-framework#107 and will be supported in MoveStdlib by move-language/move#566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants