Home » Developing U++ » U++ Developers corner » Refactoring Moveable
Refactoring Moveable [message #60744] |
Fri, 23 August 2024 08:52  |
 |
mirek
Messages: 14261 Registered: November 2005
|
Ultimate Member |
|
|
In order to make U++ more compatible and future proof, I am changing Moveable mechanisms a bit. U++ will now use C++17 inline template features to to simplify Moveable and allow putting "non-U++ guest types" in Vector/BiVector/Index. On the way I hope to fix some other problems (e.g. auto [a, b] = MakeTuple("x", 1) does not work yet) and remove all "dangerous" (ok, all possibly undefined behaviour) code, except Moveable, which is de facto standard now anyway ( https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p11 44r10.html).
Development is so far in the branch Core2024, critical part for your kind review:
https://github.com/ultimatepp/ultimatepp/blob/3638778b2e0e18 19622424a70a7f04ef0950741d/uppsrc/Core/Topt.h#L158
This now works:
template <>
inline constexpr bool Upp::is_upp_guest<std::string> = true;
template<> inline hash_t Upp::GetHashValue(const std::string& a)
{
return memhash(a.data(), a.length());
}
CONSOLE_APP_MAIN
{
{
Vector<std::string> h;
for(int i = 0; i < 20; i++)
h << AsString(i).ToStd();
RDUMP(h);
Vector<int> rem = { 1, 2, 3 };
h.Remove(rem);
RDUMP(h);
h.RemoveIf([&](int i) { return h[i].back() == '8'; });
RDUMP(h);
Vector<std::string> n = { "21", "22", "23" };
h.Insert(2, n);
RDUMP(h);
h.Insert(2, pick(n));
RDUMP(h);
h.Remove(2, 3);
RDUMP(h);
}
{
Index<std::string> x { "one", "two", "three" };
RDUMP(x);
RDUMP(x.Find("two"));
}
}
(This works legally, using std::move instead of memmove/memcpy for std::string).
[Updated on: Fri, 23 August 2024 08:54] Report message to a moderator
|
|
|
Re: Refactoring Moveable [message #60775 is a reply to message #60744] |
Sun, 08 September 2024 13:18   |
Oblivion
Messages: 1210 Registered: August 2007
|
Senior Contributor |
|
|
Hello Mirek,
Good to be on C++17
Hovewer, this seems to break a lot of things.
For example, If I derive something from MoveableAndDeepCopyOption<T>, which is now derived from TriviallyRelocatable<T> (Say, T = Vector<T>, which was possible up until now) then I can't access the methods or members of T.
Reason: TriviallyRelocatable<T> is defined as:
template <class T>
struct TriviallyRelocatable {};
Any ideas on how to proceed, or am I missing something?
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sun, 08 September 2024 13:19] Report message to a moderator
|
|
|
Re: Refactoring Moveable [message #60776 is a reply to message #60775] |
Sun, 08 September 2024 15:41   |
 |
mirek
Messages: 14261 Registered: November 2005
|
Ultimate Member |
|
|
Oblivion wrote on Sun, 08 September 2024 13:18Hello Mirek,
Good to be on C++17
Hovewer, this seems to break a lot of things.
For example, If I derive something from MoveableAndDeepCopyOption<T>, which is now derived from TriviallyRelocatable<T> (Say, T = Vector<T>, which was possible up until now) then I can't access the methods or members of T.
Reason: TriviallyRelocatable<T> is defined as:
template <class T>
struct TriviallyRelocatable {};
Any ideas on how to proceed, or am I missing something?
Best regards,
Oblivion
Uhm, normal use is like
struct Foo : MoveableAndDeepCopyOption<Foo> {
...
};
- obviously, you can access methods of Foo in Foo...
Example of what you need?
Note: There is one small issue I was unable to solve. U++ had two parameter Moveable, where second parameter was optional base class. It is supposed to help with MSC++ big with empty base class optimisations. It does not seem possible to use template magic with that which would go well MSC++ optimiser, putting Moveable first in the base class list seems to work fine wrt MSC++ optimisation and it really was used very sparsely even in U++ code and I guess almost never in client code.
Anyway
struct Foo : Moveable<Foo, FooBase> ...
now has to be rewritten as
struct Foo : Moveable<Foo>, FooBase ...
[Updated on: Sun, 08 September 2024 15:42] Report message to a moderator
|
|
|
|
Re: Refactoring Moveable [message #61378 is a reply to message #60777] |
Thu, 02 January 2025 21:41   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
A little bit of criticism.
Code below won't compile out of the box:
namespace test {
struct Test;
}
namespace test {
struct Test : Moveable<Test> {
Vector<Test> children;
};
}
Adding of
template <> inline constexpr bool is_upp_guest<test::Test> = true;
won't help.
You need to add
template <> inline constexpr bool is_trivially_relocatable<test::Test> = true;
All this stuff is inconvenient and unnatural.
And I have no idea how to make code below compile.
struct Test01;
struct Test01 {
struct Test02 : Moveable<Test02> {
Vector<Test02> children;
};
};
Regards,
Novo
|
|
|
|
Re: Refactoring Moveable [message #61383 is a reply to message #61380] |
Sat, 04 January 2025 06:46   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Fri, 03 January 2025 02:37
Do we want to go there?
Something has to be done. IMHO, a situation when very simple code cannot be compiled is unacceptable.
mirek wrote on Fri, 03 January 2025 02:37
Or any other ideas?
Please give me some time. I'll check with my old code where I was doing autodetection. Maybe I'll find something interesting.
Regards,
Novo
|
|
|
|
|
Goto Forum:
Current Time: Wed Jun 11 03:55:02 CEST 2025
Total time taken to generate the page: 0.05911 seconds
|