-
Notifications
You must be signed in to change notification settings - Fork 58
/
unique.cpp
36 lines (31 loc) · 842 Bytes
/
unique.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// unique.cpp - std::unique from the STL
#include <algorithm>
#include <xutility>
#include "G5260.h"
using namespace xll;
AddIn xai_unique(
Function(XLL_LPOPER, L"?xll_unique", L"XLL.UNIQUE")
.Arg(XLL_LPOPER, L"range", L"is a range.")
.FunctionHelp(L"Remove adjacent duplicate entries from range.")
.Category(CATEGORY)
);
LPOPER WINAPI xll_unique(LPOPER po)
{
#pragma XLLEXPORT
static OPER o;
try {
auto e = std::unique(po->begin(), po->end());
if (po->rows() == 1) {
o.resize(1, (COL)std::distance(po->begin(), e));
}
else {
o.resize((RW)std::distance(po->begin(), e), 1);
}
std::copy(po->begin(), e, o.begin());
}
catch (const std::exception& ex) {
XLL_ERROR(ex.what());
o = OPER(xlerr::NA);
}
return &o;
}