What's C++'s `using` equivalent in golang

后端 未结 4 502
挽巷
挽巷 2021-01-18 00:47

What\'s C++\'s using some_namespace::object equivalent in golang?

According to the question here I can get using namespace common with sta

4条回答
  •  春和景丽
    2021-01-18 01:31

    The following code comes close in terms of readability, but is less efficient, since the compiler cannot inline function calls anymore.

    import (
        "fmt"
        "strings"
    )
    
    var (
        Sprintf = fmt.Sprintf
        HasPrefix = strings.HasPrefix
    )
    

    And, it has the side-effect of importing the names fmt and strings into the file scope, which is something that C++'s using does not do.

提交回复
热议问题