-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
111 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include <locale> | ||
#include <sstream> | ||
#include <type_traits> | ||
|
||
#include "core/common/make_string.h" | ||
|
||
namespace onnxruntime { | ||
|
||
namespace detail { | ||
|
||
template <typename Separator> | ||
ORT_FORCEINLINE void StringJoinImpl(Separator&& separator, std::ostringstream& ss) noexcept { | ||
} | ||
|
||
template <typename Separator, typename T> | ||
ORT_FORCEINLINE void StringJoinImpl(Separator&& separator, std::ostringstream& ss, T&& t) noexcept { | ||
ss << std::forward<Separator>(separator) << std::forward<T>(t); | ||
} | ||
|
||
template <typename Separator, typename T, typename... Args> | ||
ORT_FORCEINLINE void StringJoinImpl(Separator&& separator, std::ostringstream& ss, T&& t, Args&&... args) noexcept { | ||
StringJoinImpl(std::forward<Separator>(separator), ss, std::forward<T>(t)); | ||
StringJoinImpl(std::forward<Separator>(separator), ss, std::forward<Args>(args)...); | ||
} | ||
|
||
template <typename Separator, typename... Args> | ||
ORT_FORCEINLINE std::string StringJoinImpl(Separator&& separator, Args&&... args) noexcept { | ||
std::ostringstream ss; | ||
StringJoinImpl(std::forward<Separator>(separator), ss, std::forward<Args>(args)...); | ||
return ss.str(); | ||
} | ||
|
||
/** | ||
* Makes a string by concatenating string representations of the arguments using the specified separator. | ||
* Uses std::locale::classic() | ||
*/ | ||
template <typename Separator, typename... Args> | ||
ORT_FORCEINLINE std::string StringJoinImplWithClassicLocale(Separator&& separator, Args&&... args) noexcept { | ||
std::ostringstream ss; | ||
ss.imbue(std::locale::classic()); | ||
StringJoinImpl(std::forward<Separator>(separator), ss, std::forward<Args>(args)...); | ||
return ss.str(); | ||
} | ||
} // namespace detail | ||
|
||
/** | ||
* Makes a string by concatenating string representations of the arguments using the specified separator. | ||
*/ | ||
template <typename Separator, typename... Args> | ||
ORT_FORCEINLINE std::string StringJoin(Separator&& separator, Args&&... args) { | ||
return detail::StringJoinImpl(separator, std::forward<Args>(args)...); | ||
Check warning on line 56 in include/onnxruntime/core/common/string_join.h GitHub Actions / Optional Lint C++
|
||
} | ||
|
||
// StringJoin versions for already-a-string types. | ||
|
||
template <typename Separator> | ||
ORT_FORCEINLINE std::string StringJoin(Separator&& /* separator */, const std::string& str) { | ||
return str; | ||
} | ||
|
||
template <typename Separator> | ||
ORT_FORCEINLINE std::string StringJoin(Separator&& /* separator */, const char* cstr) { | ||
Check warning on line 67 in include/onnxruntime/core/common/string_join.h GitHub Actions / Optional Lint C++
|
||
return cstr; | ||
} | ||
|
||
} // namespace onnxruntime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#if defined(_MSC_VER) | ||
#define ORT_FORCEINLINE __forceinline | ||
#else | ||
#define ORT_FORCEINLINE __attribute__((always_inline)) inline | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters