Skip to content

Commit ae757ad

Browse files
committed
v0.7.0 - reworked conversion operators for 1D basic_vector and indexed_vector so they convert more easily to scalar type
1 parent b2801d1 commit ae757ad

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ This may be a single header library, but if Visual Studio is being used, we reco
130130
131131
## Status
132132
133-
Current version: `v0.6.6`
133+
Current version: `v0.7.0`
134134
135135
* **All the vector and matrix functionality is implemented.**
136136
* First pass at test coverage. Everything major has some tests, but code coverage is not 100%.
137-
* [Released v0.6.5](https://github.com/davidbrowne/dsga/releases/tag/v0.6.5)
137+
* [Released v0.7.0](https://github.com/davidbrowne/dsga/releases/tag/v0.7.0)
138138
139139
### The next steps
140140
* Example projects: need small, medium, and large examples. The quick peek at the top of this page is a start, as is a [more detailed generic version of the example](docs/DETAILS.md#detailed-generic-example).
@@ -151,7 +151,7 @@ More in depth explanation can be found in the [details](docs/DETAILS.md).
151151
152152
This project uses [doctest](https://github.com/onqtam/doctest) for testing. We occasionally use [nanobench](https://github.com/martinus/nanobench) for understanding implementation tradeoffs.
153153
154-
Both MSVC and gcc (for Windows and on Ubuntu on WSL2) pass all the tests. clang for Windows passes, but there is 1 test out of 1806 that fails for clang-14 on Ubuntu.
154+
Both MSVC and gcc (for Windows and on Ubuntu on WSL2) pass all the tests. clang for Windows passes, but there is 1 test out of 1808 that fails for clang-14 on Ubuntu.
155155
156156
The tests have been most recently run on:
157157
@@ -164,7 +164,7 @@ The tests have been most recently run on:
164164
[doctest] run with "--help" for options
165165
===============================================================================
166166
[doctest] test cases: 81 | 81 passed | 0 failed | 0 skipped
167-
[doctest] assertions: 1822 | 1822 passed | 0 failed |
167+
[doctest] assertions: 1824 | 1824 passed | 0 failed |
168168
[doctest] Status: SUCCESS!
169169
```
170170
@@ -175,7 +175,7 @@ The tests have been most recently run on:
175175
[doctest] run with "--help" for options
176176
===============================================================================
177177
[doctest] test cases: 81 | 81 passed | 0 failed | 0 skipped
178-
[doctest] assertions: 1822 | 1822 passed | 0 failed |
178+
[doctest] assertions: 1824 | 1824 passed | 0 failed |
179179
[doctest] Status: SUCCESS!
180180
```
181181
@@ -188,7 +188,7 @@ Performs all the unit tests except where there is lack of support for ```std::is
188188
[doctest] run with "--help" for options
189189
===============================================================================
190190
[doctest] test cases: 81 | 81 passed | 0 failed | 0 skipped
191-
[doctest] assertions: 1806 | 1806 passed | 0 failed |
191+
[doctest] assertions: 1808 | 1808 passed | 0 failed |
192192
[doctest] Status: SUCCESS!
193193
```
194194
@@ -201,7 +201,7 @@ Performs all the unit tests except where there is lack of support for ```std::is
201201
[doctest] run with "--help" for options
202202
===============================================================================
203203
[doctest] test cases: 81 | 81 passed | 0 failed | 0 skipped
204-
[doctest] assertions: 1822 | 1822 passed | 0 failed |
204+
[doctest] assertions: 1824 | 1824 passed | 0 failed |
205205
[doctest] Status: SUCCESS!
206206
```
207207
@@ -223,7 +223,7 @@ swizzle_test.cxx:1841: ERROR: CHECK_UNARY( std::is_trivial_v<dmat4> ) is NOT cor
223223

224224
===============================================================================
225225
[doctest] test cases: 81 | 80 passed | 1 failed | 0 skipped
226-
[doctest] assertions: 1806 | 1805 passed | 1 failed |
226+
[doctest] assertions: 1808 | 1807 passed | 1 failed |
227227
[doctest] Status: FAILURE!
228228
```
229229

include/dsga.hxx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
// version info
2929

3030
constexpr inline int DSGA_MAJOR_VERSION = 0;
31-
constexpr inline int DSGA_MINOR_VERSION = 6;
32-
constexpr inline int DSGA_PATCH_VERSION = 6;
31+
constexpr inline int DSGA_MINOR_VERSION = 7;
32+
constexpr inline int DSGA_PATCH_VERSION = 0;
3333

3434
namespace dsga
3535
{
@@ -1553,19 +1553,18 @@ namespace dsga
15531553
return *this;
15541554
}
15551555

1556-
// scalar conversion operator
1556+
//
1557+
// scalar conversion operators
1558+
//
1559+
15571560
// this is extremely important and is only for indexed_vector of [Count == 1]
1558-
template <typename U>
1559-
requires implicitly_convertible_to<T, U>
1560-
constexpr operator U() const noexcept
1561+
constexpr operator T() const noexcept
15611562
{
1562-
return static_cast<U>(value[I]);
1563+
return value[I];
15631564
}
15641565

1565-
// scalar conversion operator
1566-
// this is extremely important and is only for indexed_vector of [Count == 1]
15671566
template <typename U>
1568-
requires (!implicitly_convertible_to<T, U>) && std::convertible_to<T, U>
1567+
requires std::convertible_to<T, U>
15691568
explicit constexpr operator U() const noexcept
15701569
{
15711570
return static_cast<U>(value[I]);
@@ -1727,20 +1726,17 @@ namespace dsga
17271726
}
17281727

17291728
//
1730-
// conversion operators
1729+
// scalar conversion operators
17311730
//
17321731

17331732
// this is extremely important and is only for basic_vector of [Size == 1]
1734-
1735-
template <typename U>
1736-
requires implicitly_convertible_to<T, U>
1737-
constexpr operator U() const noexcept
1733+
constexpr operator T() const noexcept
17381734
{
1739-
return static_cast<U>(store.value[0u]);
1735+
return store.value[0u];
17401736
}
17411737

17421738
template <typename U>
1743-
requires (!implicitly_convertible_to<T, U>) && std::convertible_to<T, U>
1739+
requires std::convertible_to<T, U>
17441740
explicit constexpr operator U() const noexcept
17451741
{
17461742
return static_cast<U>(store.value[0u]);

tests/conversion_test.cxx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,25 +524,28 @@ TEST_SUITE("test conversions")
524524
{
525525
// the three conversion operators
526526

527-
int val1 = cx_three.y; // #1 to scalar type
528-
iscal val2 = cx_three.x; // #2 implicit conversion operator
529-
auto val3 = fscal(cx_three.z); // #3 explicit cast needed to invoke conversion operator
527+
int val1 = cx_three.y; // implicit conversion
528+
dscal val2{1};
529+
float val3 = static_cast<float>(cx_three.z); // explicit conversion
530+
auto val4 = std::asin(val2.x); // implicit conversion
530531

531532
CHECK_EQ(val1, 5);
532533
CHECK_NE(val1, 4);
533534

534-
CHECK_EQ(val2, iscal(4));
535+
CHECK_EQ(val2, 1.0);
535536
CHECK_NE(val2, iscal(0));
536537

537538
CHECK_EQ(val3, fscal(6.0f));
538539
CHECK_NE(val3, fscal(4.0f));
540+
541+
CHECK_EQ(val4, std::asin(1.0));
539542
}
540543

541544
SUBCASE("2D indexed_vector conversions")
542545
{
543546
// the two conversion operators
544547

545-
ivec2 val1 = cx_three.yz; // #1 implicit conversion
548+
ivec2 val1 = cx_three.yz; // #1 implicit conversion
546549
auto val2 = fvec2(cx_three.xy); // #2 explicit cast needed to invoke conversion operator
547550

548551
CHECK_EQ(val1, ivec2(5, 6));
@@ -556,7 +559,7 @@ TEST_SUITE("test conversions")
556559
{
557560
// the two conversion operators
558561

559-
ivec3 val1 = cx_three.yzy; // #1 implicit conversion
562+
ivec3 val1 = cx_three.yzy; // #1 implicit conversion
560563
auto val2 = fvec3(cx_three.zzx); // #2 explicit cast needed to invoke conversion operator
561564

562565
CHECK_EQ(val1, ivec3(5, 6, 5));
@@ -570,7 +573,7 @@ TEST_SUITE("test conversions")
570573
{
571574
// the two conversion operators
572575

573-
ivec4 val1 = cx_three.yzyx; // #1 implicit conversion
576+
ivec4 val1 = cx_three.yzyx; // #1 implicit conversion
574577
auto val2 = fvec4(cx_three.zxyy); // #2 explicit cast needed to invoke conversion operator
575578

576579
CHECK_EQ(val1, ivec4(5, 6, 5, 4));
@@ -586,17 +589,22 @@ TEST_SUITE("test conversions")
586589
// the only basic_vector with conversion operators is
587590
// for 1D, as we want them to mimic the scalar type.
588591

589-
const int val1 = cx_one; // #1 implicit conversion
590-
[[maybe_unused]] float f2 = cx_one; // #1 implicit conversion
592+
const int val1 = cx_one; // implicit conversion
593+
[[maybe_unused]] float f2 = static_cast<float>(cx_one); // explicit conversion
591594

592595
const fscal fone = 9.9f;
593-
const int val2 = static_cast<int>(fone); // #2 explicit conversion
596+
const int val2 = static_cast<int>(fone); // explicit conversion
597+
598+
dscal dval = 1.0;
599+
auto val3 = std::asin(dval); // implicit conversion
594600

595601
CHECK_EQ(val1, 9);
596602
CHECK_NE(val1, 0);
597603

598604
CHECK_EQ(val2, 9);
599605
CHECK_NE(val2, 0);
606+
607+
CHECK_EQ(val3, std::asin(1.0));
600608
}
601609

602610
TEST_CASE("basic_vector conversion constructors")

0 commit comments

Comments
 (0)