Skip to content

Commit 48a89c1

Browse files
committed
Permutation/BipartitePermutation is a bit more movable + {inner,outer}(Perm&&) move when possible
1 parent 5846dcb commit 48a89c1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/TiledArray/permutation.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ class BipartitePermutation {
733733
init();
734734
}
735735

736+
BipartitePermutation(Permutation&& p, index_type second_partition_size = 0)
737+
: base_(std::move(p)), second_size_(second_partition_size) {
738+
init();
739+
}
740+
736741
BipartitePermutation(const Permutation& first, const Permutation& second)
737742
: second_size_(second.size()) {
738743
vector<index_type> base;
@@ -790,9 +795,14 @@ class BipartitePermutation {
790795
}
791796

792797
/// \return reference to the first partition
793-
const Permutation& first() const { return first_; }
798+
const Permutation& first() const& { return first_; }
799+
/// \return reference to the second partition
800+
const Permutation& second() const& { return second_; }
801+
802+
/// \return rvalue-reference to the first partition
803+
Permutation&& first() && { return std::move(first_); }
794804
/// \return reference to the second partition
795-
const Permutation& second() const { return second_; }
805+
Permutation&& second() && { return std::move(second_); }
796806

797807
/// \return the size of the first partition
798808
index_type first_size() const { return this->size() - second_size_; }
@@ -870,6 +880,8 @@ inline auto inner(const Permutation& p) {
870880
// temporary
871881
inline auto outer(const Permutation& p) { return p; }
872882

883+
inline Permutation&& outer(Permutation&& p) { return std::move(p); }
884+
873885
inline auto inner_size(const Permutation& p) {
874886
abort();
875887
return 0;
@@ -879,8 +891,16 @@ inline auto outer_size(const Permutation& p) { return p.size(); }
879891

880892
inline auto inner(const BipartitePermutation& p) { return p.second(); }
881893

894+
inline Permutation&& inner(BipartitePermutation&& p) {
895+
return std::move(p).second();
896+
}
897+
882898
inline auto outer(const BipartitePermutation& p) { return p.first(); }
883899

900+
inline Permutation&& outer(BipartitePermutation&& p) {
901+
return std::move(p).first();
902+
}
903+
884904
inline auto inner_size(const BipartitePermutation& p) {
885905
return p.second_size();
886906
}

0 commit comments

Comments
 (0)