Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ option(disable_native_wchar_t "Disable the use of wchar_t as a native distinct t
if (MSVC)
add_compile_options(/W4 /WX)
# add_compile_options(/Wall)
add_compile_options(/wd4018) # '_': signed/unsigned mismatch [builtin relop]
add_compile_options(/wd4459) # declaration of 'foo' hides global declaration
add_compile_options(/wd4820) # 'n' bytes padding added after data member 'foo'
add_compile_options(/wd4514) # 'x': unreferenced inline function has been removed
add_compile_options(/wd5039) # 'x': pointer or reference to potentially throwing function passed to 'extern "C"'
add_compile_options(/wd4625) # 'x': copy constructor was implicitly defined as deleted
add_compile_options(/wd5026) # 'x': move constrcutor was implicitly defined as deleted
add_compile_options(/wd4626) # 'x': assignment operator was implicitly defined as deleted
add_compile_options(/wd5027) # 'x': move assignment operator was implicitly defined as deleted
add_compile_options(/wd4710) # 'x': function not inlined
add_compile_options(/wd4820) # 'n' bytes padding added after data member 'foo'
add_compile_options(/wd5026) # 'x': move constrcutor was implicitly defined as deleted
add_compile_options(/wd5027) # 'x': move assignment operator was implicitly defined as deleted
add_compile_options(/wd5039) # 'x': pointer or reference to potentially throwing function passed to 'extern "C"'

# string(REGEX REPLACE "/O[1-2]" "/Od" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions archive/chonk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# What is a "chonk"

The chonk library is equivalent to what I later discovered already had a name:

`std::inline_vector`

It turns out that the proposal to the standards committee even had a
proposed implementation that was published on Godbolt. I picked it up,
fixed a few things that were alien to MSVC, changed the names to not
be invalid for a library to provide (leading underscores, trailing
underscores, invading the `std::` namespace) and put it in the
m_inline_vector library.

The m_chonk unit tests even passed with it on the first try, although
they were pretty minimal at that point.

Chonk has an additional feature that the std::inline_vector<> lacks
which is that the insert() member function for m::chonk<> has a
callout for the overflow element. This is designed to make implementation
of a chonk that is part of a list of chonks or vector of chonks
easier.

For this reason, the chonk library is moved under the `archive` section.
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,90 @@ namespace m
}
#endif

#if 0
/// <summary>
/// If `pos` is a valid position in `*this`, shifts elements after
/// `pos` down and inserts `value` in that position.
///
/// If this would move an element off the end of the chonk, invokes
/// fn(std::move(value)).
/// </summary>
/// <typeparam name="Fn"></typeparam>
/// <param name="pos"></param>
/// <param name="fn"></param>
/// <param name="value"></param>
/// <returns></returns>
template <typename Fn>
requires(std::invocable<Fn, value_type &&>)
iterator
insert(const_iterator pos, T&& value)
insert(const_iterator pos, Fn&& fn, value_type const& value)
{
//
M_INTERNAL_ERROR_CHECK(is_valid_iterator(pos));

M_INTERNAL_ERROR_CHECK(m_size <= N);

if (m_size == N)
{
if (pos.index() == m_size)
{
// kind of weird when the pos is at the end and the chonk
// is full, but there's a reasonable approach to handling
// it: pass the value along as the overflow. To do that
// we have to construct an instance.
value_type v{value};
std::invoke(std::forward<Fn>(fn), std::move(v));
return iterator(this, N);
}

std::invoke(std::forward<Fn>(fn), std::move(*ptr(m_size - 1)));
}

auto pos_ptr = pos.ptr();
move_unchecked_internal(pos_ptr, ptr(m_size), pos_ptr + 1);
*pos_ptr = value;
if (m_size != N)
m_size++;
return iterator(this, pos.index());
}

/// <summary>
/// If `pos` is a valid position in `*this`, shifts elements after
/// `pos` down and inserts `value` in that position.
///
/// If this would move an element off the end of the chonk, invokes
/// fn(std::move(value)).
/// </summary>
/// <typeparam name="Fn"></typeparam>
/// <param name="pos"></param>
/// <param name="fn"></param>
/// <param name="value"></param>
/// <returns></returns>
template <typename Fn>
requires(std::invocable<Fn, value_type &&>)
iterator
insert(const_iterator pos, Fn&& fn, value_type&& value)
{
M_INTERNAL_ERROR_CHECK(is_valid_iterator(pos));

M_INTERNAL_ERROR_CHECK(m_size <= N);

if (m_size == N)
{
if (pos.index() == m_size)
{
std::invoke(std::forward<Fn>(fn), std::move(value));
return iterator(this, N);
}

std::invoke(std::forward<Fn>(fn), std::move(*ptr(m_size - 1)));
}

auto pos_ptr = pos.ptr();
move_unchecked_internal(pos_ptr, ptr(m_size), pos_ptr + 1);
*pos_ptr = std::move(value);
if (m_size != N)
m_size++;
return iterator(this, pos.index());
}
#endif

#if 0
iterator
Expand All @@ -575,7 +652,7 @@ namespace m

#if 0
template <typename InputIt, typename SentinelT>
requires(std::sentinel_for<SentinelT, InputIt>)
requires(std::sized_sentinel_for<SentinelT, InputIt>)
iterator
insert(const_iterator pos, InputIt first, SentinelT last)
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ add_subdirectory(atomic)
add_subdirectory(block_buffer)
add_subdirectory(byte_streams)
add_subdirectory(cast)
add_subdirectory(chonk)
add_subdirectory(chrono)
add_subdirectory(command_options)
add_subdirectory(csv)
add_subdirectory(debugging)
add_subdirectory(error_handling)
add_subdirectory(filesystem)
add_subdirectory(googletest)
add_subdirectory(inplace_vector)
add_subdirectory(io)
add_subdirectory(math)
add_subdirectory(memory)
Expand Down
13 changes: 13 additions & 0 deletions src/libraries/inplace_vector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.23)

add_library(m_inplace_vector STATIC)

add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)

list(APPEND m_installation_targets
m_inplace_vector
)

set(m_installation_targets ${m_installation_targets} PARENT_SCOPE)
5 changes: 5 additions & 0 deletions src/libraries/inplace_vector/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.23)

target_sources(m_inplace_vector PUBLIC FILE_SET HEADERS FILES
m/inplace_vector/inplace_vector.h
)
Loading
Loading