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

Remove templates.h #8746

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions ydb/core/tablet_flat/flat_cxx_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <ydb/core/tablet_flat/flat_database.h>
#include <ydb/core/util/tuples.h>
#include <ydb/core/util/templates.h>
#include <ydb/core/base/blobstorage_common.h>

#include <util/system/type_name.h>
#include <util/system/unaligned_mem.h>
#include <library/cpp/containers/stack_vector/stack_vec.h>
#include <type_traits>
#include <utility>

// https://wiki.yandex-team.ru/kikimr/techdoc/db/cxxapi/nicedb/
Expand Down Expand Up @@ -647,6 +647,18 @@ enum class EMaterializationMode {
NonExisting,
};

namespace NDetail {
template <typename T>
class HasDefault
{
private:
template <typename C> static std::true_type test(decltype(C::Default)) ;
template <typename C> static std::false_type test(...);
public:
static constexpr bool value = decltype(test<T>(0))::value;
};
}

struct Schema {
template <typename T>
struct Precharger {
Expand Down Expand Up @@ -1437,7 +1449,7 @@ struct Schema {
}

template <typename ColumnType>
auto GetValueOrDefault(typename ColumnType::Type defaultValue = GetDefaultValue<ColumnType>(SFINAE::special())) const {
auto GetValueOrDefault(typename ColumnType::Type defaultValue = GetDefaultValue<ColumnType>()) const {
Y_DEBUG_ABORT_UNLESS(IsReady(), "Rowset is not ready");
Y_DEBUG_ABORT_UNLESS(IsValid(), "Rowset is not valid");
typename ColumnType::Type value(HaveValue<ColumnType>() ? GetColumnValue<ColumnType>() : defaultValue);
Expand All @@ -1462,24 +1474,19 @@ struct Schema {
return DbgPrintTuple(Iterator.GetKey(), typeRegistry) + " -> " + DbgPrintTuple(Iterator.GetValues(), typeRegistry);
}

template <typename ColumnType, typename SFINAE::type_check<decltype(ColumnType::Default)>::type = 0>
static decltype(ColumnType::Default) GetNullValue(SFINAE::special) {
return ColumnType::Default;
}

template <typename ColumnType>
static typename ColumnType::Type GetNullValue(SFINAE::general) {
return typename ColumnType::Type();
}

template <typename ColumnType, typename SFINAE::type_check<decltype(ColumnType::Default)>::type = 0>
static decltype(ColumnType::Default) GetDefaultValue(SFINAE::special) {
return ColumnType::Default;
static typename ColumnType::Type GetNullValue() {
return GetDefaultValue<ColumnType>();
}

template <typename ColumnType>
static typename ColumnType::Type GetDefaultValue(SFINAE::general) {
return typename ColumnType::Type();
static typename ColumnType::Type GetDefaultValue() {
if constexpr (NDetail::HasDefault<ColumnType>::value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it would be much easier to use "requires" statement for that

return ColumnType::Default;
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't write "else" on a new line

return typename ColumnType::Type();
}
}

NTable::TIteratorStats* Stats() const {
Expand All @@ -1499,7 +1506,7 @@ struct Schema {
auto& cell = tuple.Columns[index];
auto type = tuple.Types[index];
if (cell.IsNull())
return GetNullValue<ColumnType>(SFINAE::special());
return GetNullValue<ColumnType>();
return TConvert<ColumnType, typename ColumnType::Type>::Convert(TRawTypeValue(cell.Data(), cell.Size(), type));
}

Expand Down
41 changes: 0 additions & 41 deletions ydb/core/util/templates.h

This file was deleted.

1 change: 0 additions & 1 deletion ydb/core/util/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ SRCS(
single_thread_ic_mock.h
stlog.cpp
stlog.h
templates.h
testactorsys.cpp
testactorsys.h
text.cpp
Expand Down
Loading